I am trying to schedule a background task using the BGTaskScheduler in the Notification Service extension but am receiving an error while trying to submit it:
(NSError) $R4 = 0x0000000157906d30 domain: "BGTaskSchedulerErrorDomain" - code: 3
Code for the task submission is pretty basic:
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
let request = BGAppRefreshTaskRequest(identifier: "task")
do {
try BGTaskScheduler.shared.submit(request)
} catch {
NSLog("Could not schedule task \(error)")
}
}
Documentation states that scheduling a task from the extension is possible but no additional info is provided: https://developer.apple.com/documentation/backgroundtasks/bgtaskscheduler?language=objc
Maybe I am missing something?