如果用户强行退出,iOS会将我的应用程序启动到后台吗? [英] Will iOS launch my app into the background if it was force-quit by the user?

查看:155
本文介绍了如果用户强行退出,iOS会将我的应用程序启动到后台吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在推送通知中使用 content-available 标志触发后台提取。我启用了 fetch 远程通知 UIBackgroundModes

I am triggering a background fetch by using the content-available flag on a push notification. I have the fetch and remote-notification UIBackgroundModes enabled.

以下是我在AppDelegate.m中使用的实现:

Here is the implementation I am using in my AppDelegate.m:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
    NSLog(@"Remote Notification Recieved");
    UILocalNotification *notification = [[UILocalNotification alloc] init];
    notification.alertBody =  @"Looks like i got a notification - fetch thingy";
    [application presentLocalNotificationNow:notification];
    completionHandler(UIBackgroundFetchResultNewData);

}

当应用在后台运行时,它工作正常。(收到通知,应用程序触发看起来像我收到通知本地通知,因为上面的代码应该这样做)。

When the app is running in the background, it works fine. (The notification is received and the app triggered the "looks like i got a notification" local notification, as the code above should do).

然而,当应用未运行时 并且收到推送通知并且内容可用 flag,应用程序未启动,且永远不会调用 didRecieveRemoteNotification 委托方法。

However, when the app is not running and a push notification is received with the content-available flag, the app is not launched and the didRecieveRemoteNotification delegate method is never called.

WWDC视频多任务的新功能(来自WWDC 2013的#204)显示:

The WWDC Video Whats New With Multitasking (#204 from WWDC 2013) shows this:

它表示当收到推送通知时应用程序已启动到后台 content-available 标志。

It says that the application is "launched into background" when a push notification is received with the content-available flag.

为什么我的应用程序没有启动到后台?

Why is my app not launching into the background?

所以真正的问题是:

用户强制退出后,iOS会执行后台任务app?

Will iOS perform background tasks after the user has force-quit the app?

推荐答案

UPDATE2:

UPDATE2:

可以使用iOS 8中引入的新PushKit框架来实现这一目标。虽然PushKit用于VoIP。因此,您的使用应该与VoIP相关,否则存在拒绝应用的风险。 (请参阅此答案)。

You can achieve this using the new PushKit framework, introduced in iOS 8. Though PushKit is used for VoIP. So your usage should be for VoIP related otherwise there is risk of app rejection. (See this answer).

UDPDATE1:

UDPDATE1:

该文档已针对 iOS8 。可以在此处阅读文档。以下是相关摘录:

The documentation has been clarified for iOS8. The documentation can be read here. Here is a relevant excerpt:


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






尽管WWDC视频没有明确说明这一点,但在开发者论坛上进行快速搜索可以解决这个问题:


Although this was not made clear by the WWDC video, a quick search on the developer forums turned this up:

https://devforums.apple.com/message/873265# 873265 (需要登录)


另请注意,如果您从应用程序切换器中杀死您的应用程序
(即向上滑动以杀死应用程序)然后操作系统将永远不会重新启动
应用程序,无论推送通知或后台提取。在这种情况下,
用户必须手动重新启动应用程序一次,然后从
点开始,将调用后台活动。 - pmarcos

该帖子是Apple员工发布的,所以我认为我可以相信这些信息是正确的。

That post was by an Apple employee so I think i can trust that this information is correct.

所以看起来应用程序被杀死了应用程序切换器(通过向上滑动),即使对于预定的后台提取,该应用也永远不会启动。

So it looks like when the app is killed from the app switcher (by swiping up), the app will never be launched, even for scheduled background fetches.

这篇关于如果用户强行退出,iOS会将我的应用程序启动到后台吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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