推送通知和后台获取模式

时间:2014-06-29 08:16:54

标签: ios objective-c cocoa-touch push-notification

我的理解是,系统会阻止您关闭或在后台运行,并允许您在向用户显示系统警报之前获取。

我必须下载一些数据,以便在用户点按推送通知时向用户显示。

我看到我的抓取活动正在向用户显示推送时执行。它允许用户在我们完成数据提取之前点击通知并启动应用。

这是对的吗?

3 个答案:

答案 0 :(得分:0)

我自己没有机会使用推送通知和后台获取模式,

但根据docs

the system sends the notification to your app (launching it if needed)
and gives it a few moments to process the notification before displaying
anything to the user. You can use those few moments 
to download content related to the push notification and
be ready to display it to the user.

据我了解,您应该有时间作出反应(下载数据)到通知之前向用户呈现内容,而不是在显示通知时

文档不提及所考虑的内容"很少时刻" (不是我见过的。)

所以下载操作可能比那些"很少时刻和#34;

希望这会有所帮助

答案 1 :(得分:0)

在iOS7中使用所谓的“静音”推送通知,您可以从服务器发送特定的静音推送。您需要在 aps 词典中添加其他键内容可用

"aps" : {
         "alert" : "alert",
         "sound" : "sound",
         "badge" : badge,
         "content-available" : 1
}

然后,您需要在项目中设置两种背景模式:远程通知和后台提取。

现在每个远程推送都会调用

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

你可以在这里实现任何背景逻辑。例如,您可以启动一些获取过程(不超过30秒!),此时或在获取完成时显示自定义本地通知(可替代标准的远程屏幕推送)。

请确保您的应用在通知中心允许推送通知,并且您可以在“设置/常规”中为您的应用启用后台应用刷新。

另一个重要的事情是静音推动工作,直到您手动从后台卸载应用程序(双击主页按钮)。

请注意,此静默机制在iOS7.1

之前无法正常工作

答案 2 :(得分:0)

即使使用UrbanAirShip等第三方,您也可以选择是否显示AlertView。 任何如何,您可以决定不显示它,启动完成块的后台提取。 之后,您可以使用本地通知来显示您需要显示的数据。

iOS 7及以下版本的行为略有不同。

如果您可以提供更多代码/实现,我可以提供更多帮助。