Hello people, can u help me with my newbie phase in this feature??
I follow the steps of documentation (https://developer.apple.com/documentation/backgroundtasks/bgtaskscheduler) and I was see the colorFeeds project. I can execute my tasks, I got "can proceed" from dasd (code 1)
code 1:
bgProcessing-com.balancin.rage:A56E88:[
{name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Can Proceed, Score: 0.35}}
{name: DeviceActivityPolicy, policyWeight: 5.000, response: {Decision: Can Proceed, Score: 0.17}}
] sumScores:59.743333, denominator:96.410000, FinalDecision: Can Proceed FinalScore: 0.619680}
I was added in info.plist permission, I created the register in didFinishLaunching (code 2) in AppDelegate, the handle and scheduler to reschedule it (code 3). I did BGProcessingTaskRequest cause I read in documentation that this type can process more than some seconds.
code 2:
BGTaskScheduler.shared.register(forTaskWithIdentifier: AppDelegate.backgroundTaskIdentifier, using: .main) { task in
os_log("%{public}@", log: OSLog(subsystem: "com.balancin.bifrost", category: "balancin.default"), type: .debug, "balancin.rage TaskMain")
guard let task = task as? BGProcessingTask else { return }
self.handleAppRefresh(task: task )
}
code 3:
func scheduleAppRefresh() {
let request = BGProcessingTaskRequest(identifier: AppDelegate.backgroundTaskIdentifier)
// Fetch no earlier than 15 minutes from now
request.earliestBeginDate = Date(timeIntervalSinceNow: 3 * 60)
do {
try BGTaskScheduler.shared.submit(request)
} catch {
print("Could not schedule app refresh: \(error)")
}
}
func handleAppRefresh(task: BGProcessingTask) {
// Schedule a new refresh task
scheduleAppRefresh()
let operation = BlockOperation {
print("BlockOperation")
os_log("%{public}@", log: OSLog(subsystem: "com.balancin.bifrost", category: "balancin.default"), type: .debug, "balancin.rage BlockOperation")
}
task.expirationHandler = {
os_log("%{public}@", log: OSLog(subsystem: "com.balancin.bifrost", category: "balancin.default"), type: .debug, "balancin.rage expirationHandler")
operation.cancel()
}
operation.completionBlock = {
os_log("%{public}@", log: OSLog(subsystem: "com.balancin.bifrost", category: "balancin.default"), type: .debug, "balancin.rage setTaskCompleted")
task.setTaskCompleted(success: !operation.isCancelled)
}
operationQueue.addOperation(operation)
}
⚠ My problem is: When I get the "can proceed" permission from IOS dasd (duetactivityschedulerdaemon) I didn't get my OSLogs (in apple device console logs app) that I declared in my code... Why?
- Where I can find my execution logs? (os_log("%{public}@", log: OSLo...)
- Did my task really executed?
- Need I to change something?
Thanks!