当应用程序在 iOS 中关闭且应用程序不在后台运行时,从推送通知中获取数据 [英] get data from push notification when app is closed in iOS and app not running in background

查看:22
本文介绍了当应用程序在 iOS 中关闭且应用程序不在后台运行时,从推送通知中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When receive a push notification and my application is totally closed, how can handle this info?

此方法只能从 NSDictionary 获取数据didFinishLaunchingWithOptions:

Only can get data from NSDictionary on this method didFinishLaunchingWithOptions: or

didReceiveRemoteNotification:

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

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

Is there a method that responds and detect if a notification has not been read?

推荐答案

你会想要实施

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

如果需要,这将启动您的应用程序,然后您需要将数据保存在某处,以便当用户接下来启动应用程序时,您获取数据并对其进行处理.

This will launch your app if needed, then you'll want to save the data somewhere so when the user next's starts the app you grab the data and do something with it.

来自 Apples Doc:

讨论

使用此方法为您的应用处理传入的远程通知.与 application:didReceiveRemoteNotification: 方法不同,它是仅当您的应用程序在前台运行时调用,系统当您的应用程序在前台运行时调用此方法或背景.此外,如果您启用了远程通知后台模式,系统启动您的应用程序(或从暂停状态)并在推送时将其置于后台状态通知到达.但是系统不会自动如果用户强制退出,则启动您的应用程序.在这种情况下,用户必须在系统之前重新启动您的应用程序或重新启动设备尝试再次自动启动您的应用.

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.

只要看看这个方法,我相信你会弄明白的:)

Just look into the method and I'm certain you'll figure it out :)

我做了一个快速的谷歌,这些看起来会有所帮助:

I did a quick google, these look like they will help:

SO 示例:didReceiveRemoteNotification:fetchCompletionHandler:从图标打开与推送通知

我看到的第一个教程:http://hayageek.com/ios-background-fetch/

这篇关于当应用程序在 iOS 中关闭且应用程序不在后台运行时,从推送通知中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆