ios - 当应用程序在 iOS 中关闭且应用程序未在后台运行时从推送通知获取数据

标签 ios objective-c push-notification

当收到推送通知并且我的应用程序已完全关闭时,如何处理此信息?

只有didFinishLaunchingWithOptions:

方法可以从NSDictionary 获取数据

didReceiveRemoteNotification:

例如:当用户打开应用程序时如何从推送通知中获取数据?而不是当用户直接打开推送通知时。

是否有一种方法可以响应并检测是否未阅读通知?

最佳答案

你会想要实现

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler

这将在需要时启动您的应用,然后您需要将数据保存在某个地方,这样当用户下次启动应用时,您可以获取数据并对其进行处理。

From Apples Doc's:

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/

相关文章:

ios - iOS 解锁时显示不同的通知文本

ios - 应用程序终止时处理推送通知

iphone - 推送通知数据检索

ios - 根据屏幕大小设置 UIImageView 宽度

ios - 检查用户在应用内购买中购买的产品

iphone - Xcode "the view outlet was not set.' 错误“

ios - 如何在 Objective-C 中将参数从 .m 传递到另一个 .m

ios - 使用Azure移动服务sdk在iOS中并行调用

ios - 重新加载 ViewController

javascript - PhoneGap - 本地手机主屏幕的按钮