Robert Munro
08/02/2022, 4:01 PMiosMain
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 sureRobert Munro
08/02/2022, 5:03 PMAnvith
01/08/2024, 3:48 AMmemScoped {
val error = interpretCPointer<ObjCObjectVar<NSError?>>(alloc(1,1).rawPtr)
isScheduled = BGTaskScheduler.sharedScheduler.submitTaskRequest(request, error)
logD("Submitted background task $isScheduled, ${error?.get(0)?.value}")
}
relevant imports
import kotlinx.cinterop.BetaInteropApi
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.ObjCObjectVar
import kotlinx.cinterop.get
import kotlinx.cinterop.interpretCPointer
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.value