繁体   English   中英

永远不会调用ReceivedRemoteNotification和DidReceiveRemoteNotification

[英]ReceivedRemoteNotification and DidReceiveRemoteNotification never get called

我们在应用程序中实现了远程推送通知。 我们想要实现的是,当我们的应用程序在后台运行时,将出现一个远程通知,用户单击该通知,我们将根据通知信息执行一些任务。 我注意到,当应用程序在后台运行时,当有通知传入时,在Appdelegate中,永远不会调用DidReceiveRemoteNotification和ReceivedRemoteNotification。 我无法从userInfo获取通知。 有人遇到过这个问题吗? 这是错误吗? 任何帮助是极大的赞赏!

谢谢李昌

确保您在真实设备上进行测试。 您需要在info.plist

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

这在您的Entitlements.plist

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

让您的AppDelegate类实现以下接口: IUNUserNotificationCenterDelegate

尝试添加它,看看它是否被调用:

    [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证书添加了某些内容,并且在对应用程序进行签名的供应配置文件中具有该证书。

暂无
暂无

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

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