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?
In the
BGTaskSchedulerErrorDomain
, code 3 is
BGTaskSchedulerErrorCodeNotPermitted
, which has an description of:
The task request could not be submitted because the appropriate background mode is not included in the
array, or its identifier was not present in theUIBackgroundModes
array in the app'sBGTaskSchedulerPermittedIdentifiers
.Info.plist
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"