I have an app in which I'm trying to receive and handle SILENT push notifications.
I'm registering for APNs as follows:
UNUserNotificationCenter.currentNotificationCenter().delegate = self
UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions([.Badge, .Sound, .Alert]) {(granted, error) in
if granted {
application.registerForRemoteNotifications()
}
}
Implemented:
func userNotificationCenter(center: UNUserNotificationCenter, didReceiveNotificationResponse response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) {
// Handle notification
}
func userNotificationCenter(center: UNUserNotificationCenter, willPresentNotification notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) {
// Handle notification
}
The app has UIBackgroundModes
fetch
and remote-notification
The APN content looks like:
{
"aps":{
"content-available":1,
"badge":0
},
"action":"shareDelete",
"shareId":633
}
When the app is in the foreground, userNotificationCenter(centre:withCompletionHandler:willPresentNotification)
is fired when the notification is received, but when the app is backgrounded, nothing happens.
I can see the APN is received by changing the badge number, but nothing is triggered in app.
What am I missing?
(Also asked on Apple dev forums)
userNotificationCenter:didReceiveNotificationResponse
isn't called – LookoutlaunchOptions
dictionary – Rudderhead