如果UIBackgroundModes中定义了远程通知和新的推送通知,iOS重启后是否会在后台启动应用程序? [英] Does iOS start app in background after reboot if remote-notification defined in UIBackgroundModes and new push notification comes?

查看:69
本文介绍了如果UIBackgroundModes中定义了远程通知和新的推送通知,iOS重启后是否会在后台启动应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个注册后台模式远程通知的iOS7应用程序:

I have an iOS7 app which registers for background mode remote-notification:

<key>UIBackgroundModes</key>
<array>
    <string>remote-notification</string>
</array>

在重新启动之前运行良好,并且应用程序在后台运行时会收到此事件:

It works fine before reboot and app gets this event while in background:

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

但是看起来在重新启动后,直到我手动启动应用程序之后,我再也没有收到此事件.

But it looks like after reboot I don't get this event anymore until I start application manually.

因此,问题是:当iOS7收到我的应用程序的静默推送通知时,是否可以使iOS7在重新启动后将我的应用程序运行到后台? 我的推送通知没有警报"字段,只有"contentAvailable"-这可能是原因吗? 我见过类似whatsapp之类的应用程序在重启后能够立即接收和显示推送通知,因此对于至少警报"类的通知而言,它似乎是可行的.

So, question is: can I make iOS7 to run my app into background after reboot when it receives silent push notification for my app? My push notifications don't have "alert" field, only "contentAvailable" - can this be a reason? I've seen apps like whatsapp being able to receive and show push notifications immediately after reboot so it looks doable for at least "alert" kind of notifications.

我知道我可以在重启后的某个时候使用重要的位置监控来重新启动应用程序,但我想避免一直在工具栏上显示位置图标.后台获取模式可以帮助您吗? 是否有任何统计信息,以后台获取模式重启应用后执行速度有多快?

I know that I can use significant location monitoring to restart app at some point after reboot but I would like to avoid showing location icon on toolbar all the time. Can background-fetch mode help with that? Is there any statistics, how fast after reboot app with background fetch mode will be executed?

推荐答案

不,它不起作用.因为您的应用在重启设备时将处于未运行状态.

No, It won't work. Because your app will be in Not Running state as you rebooted your device.

根据Apple文档,新的多任务API(获取和远程通知)仅在应用处于 suspended/background/foreground 状态时有效.如果应用处于背景/前景状态,则会触发application:didReceiveRemoteNotification:fetchCompletionHandler.如果应用处于已暂停状态,则将触发-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions. 在您的情况下,该应用程序处于未运行状态,因为永远不会触发application:didReceiveRemoteNotification:fetchCompletionHandler.

As per apple doc, the new multitasking API(fetch and remote-notification) will work only when the app in the suspended/background/foreground state. If the app is in background/foreground state, then application:didReceiveRemoteNotification:fetchCompletionHandler will get triggered. If the app is in suspended state, then -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions will get triggered. In your case the app is in Not Running state, because of that application:didReceiveRemoteNotification:fetchCompletionHandler is never get triggered.

请参考

Please refer apple doc for more about app states.

这篇关于如果UIBackgroundModes中定义了远程通知和新的推送通知,iOS重启后是否会在后台启动应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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