Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 10 silent push notification not triggering backgrounded app

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)

like image 337
Ashley Mills Avatar asked Nov 03 '16 16:11

Ashley Mills


People also ask

Will iOS awake my app when I receive silent push notification?

Yes. It will. When you click on that. Yeah its ok but being push notification is silent,you are not able to view any alert and cant click.

Does push notification wake up app?

the app doesn't wake up. We use this mechanism to send device location to our server.

How do I send silent push notifications?

There are two ways users can receive silent push notifications on Android. Users can long press on a notification to get an option to display notifications silently. Users can also enable silent notifications by heading to Settings > App & Notifications > Search for app and choose> Notifications, and turn it off.

What is silent push notification?

They arrive on the mobile device and sit in the notification tray until read or dismissed. Users can choose to mute their notifications and receive silent push notifications instead of being alerted to every new push that arrives. They can activate this on iOS or Android from their individual settings pages.


1 Answers

Method

func userNotificationCenter(center: UNUserNotificationCenter, didReceiveNotificationResponse response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) {
    // Handle notification
}

called when user taps on notification or check it on Apple Watch:

Called to let your app know which action was selected by the user for a given notification.

You need to implement the old method

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

}
like image 97
OgreSwamp Avatar answered Sep 20 '22 14:09

OgreSwamp