gpt4 book ai didi

ios - 获取收到远程通知的日期

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

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

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

最佳答案

在应用程序委托(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/

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