Hi,
Question
In iOS 12, will a UNNotificationServiceExtension ever be allowed to add local notifications using UNUserNotificationCenter? If it requires an entitlement to be added, which entitlement is needed?
Background
We have implemented an App extension that extends UNNotificationServiceExtension.
On iOS 10 and 11 we have successfully used it to implement a feature in our App that lets the user choose to get reminders of remote notifications if they have not responded to them. The UNNotificationServiceExtension examines the content of each remote notification and, if they meet the criteria the user has configured for reminders, we construct a UNNotificationRequest and use UNUserNotificationCenter.current().add() to schedule a local notification.
This works on iOS 10 and 11, but not on iOS 12 beta 12 (16A5366a). Instead the extension gets an error "Notifications are not allowed for this application" and the device logs contain the entry
SpringBoard 2018-09-11 11:53:42.581817 -0700 Not allowing service extension 'com.myapp.MyService' to request user notifications at this time
I have tried changing the extension to request authorization before adding the local notification:
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound]) { (granted, grantError) in
if let err = grantError {
Logger.log("grantError: \(err.localizedDescription)")
} else if granted {
Logger.log("requestAuthorization was granted")
scheduleLocalNotifications(request: request, accountSettings: accountSettings)
} else {
Logger.logWarn("requestAuthorization was not granted")
}
}
but this results in the same "Notifications are not allowed for this application" error and now the iOS device logs contain:
SpringBoard 2018-09-11 10:53:47.496252 -0700 [com.myapp] Requesting authorization with options 6
SpringBoard 2018-09-11 10:53:47.498404 -0700 Not allowing service extension 'com.myapp.MyService' to request user notifications at this time
SpringBoard 2018-09-11 10:53:47.498801 -0700 [com.myapp] Requesting authorization failed because of missing entitlement
MyService 2018-09-11 10:53:47.499657 -0700 [com.myapp] Requested authorization [ didGrant: 0 hasError: 1 hasCompletionHandler: 1 ]
Hence my question: is what I am trying to do just not allowed in iOS 12, or is there an entitlement I need to add to my extension?