ios - 如果用户强制退出,iOS 是否会将我的应用程序启动到后台?

标签 ios ios7 push-notification apple-push-notifications

我通过在推送通知上使用 content-available 标志来触发后台获取。我启用了 fetchremote-notification UIBackgroundModes

这是我在 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);

}

当应用程序在后台运行时,它工作正常。(收到通知并且应用程序触发了“看起来我收到了通知”本地通知,正如上面的代码应该做的那样).

但是,当应用未运行并且收到带有 content-available 标志的推送通知时,应用未启动并且永远不会调用 didRecieveRemoteNotification 委托(delegate)方法。

WWDC 视频 Whats New With Multitasking(来自 WWDC 2013 的#204)显示:enter image description here

它表示当收到带有 content-available 标志的推送通知时,应用程序“启动到后台”。

为什么我的应用没有在后台启动?

所以真正的问题是:

iOS 会在用户强制退出应用后执行后台任务吗?

最佳答案

更新 2:

可以使用 iOS 8 中引入的新 PushKit 框架实现这一点。尽管 PushKit 用于 VoIP。所以您的使用应该与 VoIP 相关,否则有应用被拒绝的风险。 (参见 this answer)。


UDPDATE1:

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

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 视频没有明确说明这一点,但在开发者论坛上快速搜索发现了这一点:

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

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 员工发布的,因此我相信此信息是正确的。

所以看起来当应用程序从应用程序切换器(通过向上滑动)被杀死时,应用程序将永远不会启动,即使对于计划的后台获取也是如此。

关于ios - 如果用户强制退出,iOS 是否会将我的应用程序启动到后台?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19068762/

相关文章:

flutter - 通知中心图标不正确

ios - 无法以编程方式导航到另一个 UIViewController iOS

ios - 从自己的类方法中调用方法

colors - 如何以编程方式制作反色 uibutton?

ios7 - 使用自动布局修复 iOS7 状态栏问题的最佳方法

iphone - iOS7 UIScrollView 在状态栏下方显示偏移内容

ios - AWS Mobile HUD AWS SNS pushManagerDidRegister 但未创建端点

iphone - 苹果推送通知在生产中不起作用

ios - 从 NSMutableArray 中删除括号

ios - 在 Storyboard 中,UIViewController 的宽度不是 iPhone 的宽度