ReceivedRemoteNotification 和 DidReceiveRemoteNotification 永远不会被调用 [英] ReceivedRemoteNotification and DidReceiveRemoteNotification never get called

查看:21
本文介绍了ReceivedRemoteNotification 和 DidReceiveRemoteNotification 永远不会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在应用中实现了远程推送通知.我们想要实现的是,当我们的应用程序在后台时,远程通知进来,用户点击通知,我们根据通知信息执行一些任务.我注意到当应用程序在后台时,当通知进来时,在 Appdelegate 中,DidReceiveRemoteNotification 和 ReceivedRemoteNotification 永远不会被调用.我无法从 userInfo 获取通知.有没有人遇到过这个问题?这是一个错误吗?非常感谢任何帮助!

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!

谢谢,立昌

推荐答案

确保您在真实设备上进行测试.你需要在你的 info.plist 中有这个:

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>

这在你的 Entitlements.plist 中:

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

让你的 AppDelegate 类实现这个接口:IUNUserNotificationCenterDelegate.

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);
    }

此外,在 Apple 开发者门户上,请确保您为 KeysApple Push Services 证书添加了一些内容,并且您在配置文件中拥有该证书那就是签署应用程序.

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.

这篇关于ReceivedRemoteNotification 和 DidReceiveRemoteNotification 永远不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆