简体   繁体   中英

ReceivedRemoteNotification and DidReceiveRemoteNotification never get called

We implemented remote push notifications in our app. What we would like to achieve is that when our app is in the background, a remote notification comes in, the user clicks on the notification, we perform some tasks based on the notification information. I noticed that when the app was in the background, when a notification came in, in Appdelegate, DidReceiveRemoteNotification and ReceivedRemoteNotification never get called. There's no way for me to get the notification from userInfo. Has anyone experienced this issue? Is this a bug? Any help is greatly appreciated!

Thanks, Lichang

Make sure that you are testing on a real device. You need to have this in your info.plist :

<key>UIBackgroundModes</key>
<array>
  <string>remote-notification</string>
</array>

and this in your Entitlements.plist :

<dict>
  <key>aps-environment</key>
  <string>development</string>
</dict>

Have your AppDelegate class implement this interface: IUNUserNotificationCenterDelegate .

Try adding this and see if it gets called:

    [Export("userNotificationCenter:willPresentNotification:withCompletionHandler:")]
    public void WillPresentNotification(UNUserNotificationCenter center, 
                           UNNotification notification, 
                           Action<UNNotificationPresentationOptions> completionHandler)
    {
        completionHandler?.Invoke(UNNotificationPresentationOptions.Alert);
    }

    public override void DidReceiveRemoteNotification(UIApplication application, 
              NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
    {
        //BACKGROUND
        //handleNotification(userInfo);
        completionHandler(UIBackgroundFetchResult.NewData);
    }

Also, on the apple developer portal, make sure that you either have added something for Keys or an Apple Push Services certificate and you have the cert in the provisioning profile that is signing the app.

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