iOS 8/9/10 background notification delegate method not working

  • I have implemented a custom push handler that conforms to the "UAPushNotificationDelegate" protocol . It has these methods similar to sample urban airship application .

    -(void)receivedBackgroundNotification:(UANotificationContent *)notificationContent completionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    // Application received a background notification
    UA_LDEBUG(@"The application received a background notification");

    // Call the completion handler
    completionHandler(UIBackgroundFetchResultNoData);
    }

    -(void)receivedForegroundNotification:(UANotificationContent *)notificationContent completionHandler:(void (^)())completionHandler {
    completionHandler();
    }

    -(void)receivedNotificationResponse:(UANotificationResponse *)notificationResponse completionHandler:(void (^)())completionHandler {
    completionHandler();
    }

    - (UNNotificationPresentationOptions)presentationOptionsForNotification:(UNNotification *)notification {
    return UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionSound;
    }

    but receivedBackgroundNotification method is not firing when I get a background notification. I can see the push notification pop up.
    I really want to make this work as I'm trying to add app icon badges manually as I'm working out of your inbox.

    thanks in advanced.

Didn't find what you were looking for?

New post

Comments

3 comments

  • Hi Rahal,

    Can you confirm you are sending background pushes to your app?

    Keep in mind that when you send a push notification to your device, the "receivedBackgroundNotification" will only fire if the kind of push you are sending is a background push. If it is not sent as a background push, that method will not fire.

    There are two other things you should make sure you've done in your app to make sure you're 100% set up.

    First, make sure you've enabled background modes for your application.

    Second, when sending a push to your device, make sure you've enabled the content-available flag. This enables the app to wake up in the background and perform some actions inside the app. This enables the background notification method to fire.

    1
  • Hi Michael

     

    Thanks a lot for your comment. I was missing "content-available flag" in the push . now it works very well..  

     

     

    0
  • Rahal,

    No problem!

    0

Please sign in to leave a comment.