OGeek|极客世界-中国程序员成长平台

标题: ios - 获取收到远程通知的日期 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 20:05
标题: ios - 获取收到远程通知的日期

我希望能够获取在 iOS 设备上收到远程通知的日期。

我正在尝试确定从我的服务器触发推送通知到在用户设备上收到它之间的延迟量。



Best Answer-推荐答案


在您的应用程序委托(delegate)的 application:didReceiveRemoteNotification:fetchCompletionHandler: 中,使用当前日期创建一个 NSDate,然后将其保存在 NSUserSettings 的数组中或直接保存在其中。

有了这个,您甚至可以拥有收到通知的历史记录,并且可以在以后处理它们。

application:didReceiveRemoteNotification:fetchCompletionHandler: 仅当您将值为 1 的 content-available 键添加到通知负载中时才会在后台调用。

来自 Apple 文档:

For a push notification to trigger a download operation, the notification’s payload must include the content-available key with its value set to 1. When that key is present, the system wakes the app in the background (or launches it into the background) and calls the app delegate’s application:didReceiveRemoteNotification:fetchCompletionHandler: method. Your implementation of that method should download the relevant content and integrate it into your app. https://developer.apple.com/library/prerelease/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

关于ios - 获取收到远程通知的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37302246/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4