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

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

问题描述

我通过在推送通知上使用 content-available 标志来触发后台获取.我启用了 fetchremote-notification 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).

但是,当应用未运行并且收到带有content-available标志的推送通知时,应用不会启动并且 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 会执行后台任务吗?

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

推荐答案

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:

文档已针对 iOS8 进行了澄清.可以在此处阅读文档.以下是相关摘录:

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

使用此方法为您的应用处理传入的远程通知.与 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.

<小时>

虽然 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

Also keep in mind that if you kill your app from the app switcher (i.e. swiping up to kill the app) then the OS will never relaunch the app regardless of push notification or background fetch. In this case the user has to manually relaunch the app once and then from that point forward the background activities will be invoked. -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天全站免登陆