简体   繁体   English

永远不会调用ReceivedRemoteNotification和DidReceiveRemoteNotification

[英]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. 我注意到,当应用程序在后台运行时,当有通知传入时,在Appdelegate中,永远不会调用DidReceiveRemoteNotification和ReceivedRemoteNotification。 There's no way for me to get the notification from userInfo. 我无法从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 : 您需要在info.plist

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

and this in your Entitlements.plist : 这在您的Entitlements.plist

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

Have your AppDelegate class implement this interface: IUNUserNotificationCenterDelegate . 让您的AppDelegate类实现以下接口: 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. 另外,在Apple开发人员门户上,请确保您已为KeysApple Push Services证书添加了某些内容,并且在对应用程序进行签名的供应配置文件中具有该证书。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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