Robert Munro

    Robert Munro

    1 month ago
    i'm trying to implement the background worker in
    iosMain
    https://medium.com/mobil-dev/background-task-with-bgtaskscheduler-1d49e22b1519 I seem to be able to get the
    BGTaskScheduler
    fine but i cant import the
    Operation
    class needed to schedule the actual work. would it be named differently? or access the
    operationQueue
    .
    override fun createBatchAndAppendBoxesToIt(
        localBatchId: String,
        batchTimestamp: Long,
        batchName: String,
        boxes: List<LocalBox>
    ) {
        val identifier = createUniqueWorkName(localBatchId)
        BGTaskScheduler.sharedScheduler.registerForTaskWithIdentifier(identifier, null) { task ->
            val request = BGAppRefreshTaskRequest(identifier)
            request.earliestBeginDate = null
            try {
                // what's this do? pointer for submitError? CPointer<ObjCObjectVar<NSError?>>?
                BGTaskScheduler.sharedScheduler.submitTaskRequest(request, null)
            } catch (e: Exception) {
                Logger.error(TAG, "Could not schedule app refresh", e)
            }
            val operation = CreateBatchWorker() // should inherit from Operation
            //task!!.expirationHandler = { operation.cancel() }
            //operation.completionBlock = { task.setTaskCompleted(!operation.isCancelled) }
            //operationQueue.addOperation(operation)
    
        }
    }
    Would it be better to make an interface and implement it in swift? not sure
    not sure if that example is good