当收到推送通知并且我的应用程序已完全关闭时,如何处理此信息?
只有didFinishLaunchingWithOptions: 或
方法可以从NSDictionary
获取数据
didReceiveRemoteNotification:
例如:当用户打开应用程序时如何从推送通知中获取数据?而不是当用户直接打开推送通知时。
是否有一种方法可以响应并检测是否未阅读通知?
最佳答案
你会想要实现
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
这将在需要时启动您的应用,然后您需要将数据保存在某个地方,这样当用户下次启动应用时,您可以获取数据并对其进行处理。
Discussion
Use this method to process incoming remote notifications for your app. Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running in the foreground, the system calls this method when your app is running in the foreground or background. In addition, if you enabled the remote notifications background mode, the system launches your app (or wakes it from the suspended state) and puts it in the background state when a push notification arrives. However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.
只需研究方法,我相信您会弄明白的:)
我快速谷歌了一下,这些看起来会有帮助:
SO 示例:didReceiveRemoteNotification: fetchCompletionHandler: open from icon vs push notification
我在上面看到的第一个教程:http://hayageek.com/ios-background-fetch/
关于ios - 当应用程序在 iOS 中关闭且应用程序未在后台运行时从推送通知获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27447443/