iOS后台模式:在后台运行位置更新后,该应用程序永不终止 [英] iOS Background Mode: After running location updates in the background, the app never terminates

查看:93
本文介绍了iOS后台模式:在后台运行位置更新后,该应用程序永不终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在后台运行位置更新。一切正常:

I'm running location updates in the background. All works well:


  • 在重要位置,应用程序在后台启动

-appDidFinishLaunching(options)被调用。


  • 我启动 LocationManager startUpdatingLocation() startMonitoringSignificantLocationChanges()

位置信息已正确收集。

一段时间后,我致电 stopUpdatingLocation()

我现阶段的程序不需要做任何事情,也不需要执行任何代码

My program at this stage doesn't need to do anything and no further code is executed

此时程序保持空闲状态。 applicationWillTerminate 不再被调用。这是预期的吗?我希望该应用程序能够再次关闭,因为不需要位置更新。

At this point the program stays idle. applicationWillTerminate is never called again. Is this expected? I'd hoped the app will shut down again as no location updates are required.

预期的行为是什么?该应用程序应该关闭还是应该永远保持空闲状态?

What's the expected behaviour? Should the app shut down or should it stay idle forever?

一旦发生这种情况,那么如果用户打开该应用程序或再次收到一个重要位置,则 appDidFinishLaunching(options)不被调用,而是 applicationDidBecomeActive

Once this happens, then if a user user opens the app or a significant location is received again, then appDidFinishLaunching(options:) is NOT called, but instead applicationDidBecomeActive.

是否可以遵循任何文档来支持预期的行为?

Is there any documentation I can follow that supports the expected behaviour?

推荐答案

是的,这里的所有内容都是预期的。 JD Wooder删除了一个正确链接文档的答案:管理应用程序的生命周期。 通常,不会主动杀死后台iOS应用。只有在需要系统资源时,它们才会被杀死。这是不可预测的,并且该应用通常在发生时不会收到 applicationWillTerminate 消息(因为该应用通常此时未运行,并且不会被唤醒)只是为了杀死它)。您的应用应同时处理冷启动( appDidFinishLaunching )和热启动( applicationDidBecomeActive )。

Yes, everything here is expected. There's a deleted answer from J.D. Wooder that correctly linked the documentation: "Managing Your App's Life Cycle." As a rule, background iOS apps are not proactively killed. They are only killed when system resources are needed. This is unpredictable, and the app typically will not receive a applicationWillTerminate message when it happens (because the app typically is not running at that point, and it won't be woken up just to kill it). Your app should handled both a cold launch (appDidFinishLaunching) and a warm launch (applicationDidBecomeActive).

从头开始重新启动应用程序非常昂贵,因此,如果没有资源压力,iOS宁愿将最近使用的内容保留在内存中。无所事事的应用非常便宜。

Restarting an app from scratch is expensive, so iOS prefers to keep recently used thing in memory if there's no resource pressure. Apps that are doing nothing are very cheap. to keep around.

请注意,iOS 13在杀死后台应用程序方面变得更加积极,而新手机上的大型摄像头正导致内存压力的消除应用也更快,因此不要长时间在后台运行。但这也很正常。

Note that iOS 13 has grown much more aggressive in killing apps in the background, and that the large cameras on new phones are leading to memory pressures that kill apps more quickly as well, so don't get too comfortable with running in the background for a long time. But it's also very normal.

这篇关于iOS后台模式:在后台运行位置更新后,该应用程序永不终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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