简体   繁体   中英

didReceiveRemoteNotification fetchCompletionHandler is not getting called in background for silent push

So I have added didReceiveRemoteNotification delegate to handle silent push notification

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler

This method should be invoked in the background to update the content before notifying the user, so that the user can open the application and be presented with new content immediately.

But this method is never getting called in background. I have tried to debug the issue but no success. Surprisingly this method is getting called properly if my app is in foreground and I am easily able to check content-available to update the UI.

Can anyone please help me with this issue that why didReceiveRemoteNotification:fetchCompletionHandler is not getting called in background ?

Enable 'Remote Notifications' in 'Background Modes' of 'Capabilities' tab in xcode.

For more information see this link

Hope this helps.

Issue was related to incorrect payload.

I was getting content-available outside aps instead it should be part of aps.

Incorrect payload:

{
   "_" = "asd-dfsd-werdsf";
   aps =     {
   };
   "content-available" = 1;
}

Correct payload:

    {
       "_" = "asd-dfsd-werdsf";
       aps =     {
       "content-available" = 1;
       };
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM