gpt4 book ai didi

c# - 在 Xamarin iOS 应用程序中使用 UIApplicationDelegate.DidReceiveRemoteNotification 处理远程通知

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:28:46 25 4
gpt4 key购买 nike

我有一个配置为接收远程通知的 Xamarin iOS 应用程序。当设备收到远程通知时,远程通知处理程序未按预期执行。

DidReceiveRemoteNotification 的实现包括对应用程序的引用、通知用户信息字典以及将在适当的 UIBackgroundFetchResult 状态下执行的完成处理程序。

    public override void DidReceiveRemoteNotification (UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
// retrieve something from a server somewhere
}

根据 Apple 的 iOS 开发人员文档,“application:didReceiveRemoteNotification:fetchCompletionHandler”的实现将在向用户显示远程通知后执行。

这包括应用程序何时处于运行状态、后台状态以及“未运行”状态。收到通知后应启动应用程序,然后在调用此方法之前将其置于后台状态。

引用: https://developer.apple.com/library/ios/documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html#jumpTo_12

在我的设备上运行时,远程通知已成功传递。但是,当在 XCode Organizer 中跟踪设备的控制台日志时,应用程序永远不会启动,并且永远不会执行“DidReceiveRemoteNotification”方法。

我做了以下事情:

  • 在应用程序的 plist 文件中选中“启用后台模式”并启用“后台获取”和“远程通知”。
  • 在我的应用程序委托(delegate)中实现了 DidReceiveRemoteNotification(UIApplication, NSDictionary, Action)。
  • 确保发送到 APN 的通知配置为标准通知 - 即不是静默通知。
  • 在以不同状态(前台、后台、未运行等)运行应用程序时向我的设备发送测试远程通知。

如果这个线程是正确的,这看起来像是 Xamarin 实现中的一个问题,但我希望其他人之前遇到过这个问题并且可以确认或提供额外的信息。 http://forums.xamarin.com/discussion/8765/handling-silent-remote-notifications

最佳答案

据我所知,DidReceiveRemoteNotification当您的应用程序正在运行并且设备收到您的应用程序的推送通知时将被调用。

当您的应用程序从推送通知启动时(即它之前没有运行),您应该阅读 AppDelegate s launchOptions didFinishLaunching 中的词典事件。

有关更多信息,请阅读 UIApplicationLaunchOptionsRemoteNotificationKey关键是。

关于c# - 在 Xamarin iOS 应用程序中使用 UIApplicationDelegate.DidReceiveRemoteNotification 处理远程通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21639626/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com