Push notification not received when App is in Background in iOS 10

后端 未结 2 996
我寻月下人不归
我寻月下人不归 2020-12-31 21:38

I\'m using FCM(Firebase Cloud Messaging) for sending push notifications in iOS.

I\'m able to receive the notification when App is in foreground state. But when the A

相关标签:
2条回答
  • 2020-12-31 22:05

    For iOS 10, we need to call the 2 methods below.

    For FOREGROUND state

    - (void)userNotificationCenter:(UNUserNotificationCenter *)center  willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler  
    {  
        NSLog( @"Handle push from foreground" );  
        // custom code to handle push while app is in the foreground  
        NSLog(@"%@", notification.request.content.userInfo);
        completionHandler(UNNotificationPresentationOptionAlert);
    } 
    

    For BACKGROUND state

    - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler  
    {  
        NSLog( @"Handle push from background or closed" );  
        // if you set a member variable in didReceiveRemoteNotification, you  will know if this is from closed or background  
        NSLog(@"%@", response.notification.request.content.userInfo);
        completionHandler();
    }  
    

    Before that, we must add the UserNotifications framework and import in the AppDelegate.h file

    #import <UserNotifications/UserNotifications.h>  
    @interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>  
    
    0 讨论(0)
  • 2020-12-31 22:05

    We've run many tests with our customers and did lots of research on the topic. iOS 10.x, especially 10.3.x has issues handling and displaying pushes. The only way to circumvent the issues is by upgrading to a newer iOS-version.

    0 讨论(0)
提交回复
热议问题