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

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

问题描述

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

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

只能从 NSDictionary获取数据 didFinishLaunchingWithOptions:

didReceiveRemoteNotification:

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

是否有一种方法可以响应并检测是否还没有读取通知?

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

推荐答案

你'll想实现

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

如果需要,这将启动你的应用程序,然后你'我想在某个地方保存数据,以便用户nex t启动应用程序,您可以获取数据并使用它执行某些操作。

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.

From Apples Doc's:


讨论

Discussion

使用此方法处理应用程序的传入远程通知。
与应用程序不同: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:

例如: didReceiveRemoteNotification:fetchCompletionHandler:从图标vs推送通知打开

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

The first tutorial i saw on it: http://hayageek.com/ios-background-fetch/

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

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