iOS 12 terminates apps in the background for no re

2019-01-30 20:21发布

Starting from iOS 12 the CLLocationManager doesn't run endless anymore in the background. The app get's terminated without a crashlog at random times. This was working fine before iOS 12.

To demonstrate this problem I've created an sample app here

The demo app just launches an CLLocationManager and keep this running in the background. While running on the background we keep track of it by logging it. The problem is that the app get terminated by iOS. The demo app is created to demonstrate this problem.

Steps to reproduce

  1. Run the app on the device
  2. Grand access to locationmanager
  3. Put the app to the background
  4. Wait for 1-48hours

Result:

  1. The app is terminated

App is terminated without any reason after random time.

Expected result:

  1. The app is still running.

How it should work

This is confirmed by an Apple engineer:

Once the CLLocationManager updates are started in the foreground and you did all the work to have it running in the background, the location updates should run endless in the background until:

  • app is force quit
  • device is rebooted
  • app stops location updates
  • app releases the CLLocationManager object
  • app crashes
  • iOS terminates the app due to memory shortage,
  • the locationManager object is released, overreleased, or overwritten. You should make sure that your view controller is not being instantiated, which then resets the locationController class. If that happens when the app is in the background, you will restart updates, which will cause the app to be eventually suspended. You should make sure the locationController is a singleton.
  • app is crashing. Check to see if there are crash logs on the device you are testing
  • iOS is terminating the app due to memory shortage. In this case, you will find JetsamEvent logs on the device that shows your app being terminated. You can check the timestamps and locate the one that is around the time your app stopped working.

2条回答
一纸荒年 Trace。
2楼-- · 2019-01-30 20:47

Together with Apple Developer Technical Support we have analyzed this issue with Sysdiagnose files. Following these guidelines you can install profiles to have more logging on your device. I don't know exactly how these logs work and where to find this issue, but Apple did this for me and came with this first analyse:

On the suspension event you observed on 2018/10/22 01:01:12:587, this is what I see (about a minute after your last activity logging)

[CllocationManag:2725] Terminating with description: { owner = ; target = rw.sp.flitsmeister.frameworks.CllocationManagerBackgroundTest; }

This is basically saing that your app was terminated, because the system needed drive space, and killed a bunch of apps so it can delete their /tmp and /Library/Caches directories. I have seen this process to be a little more aggressive in iOS 12, but seeing you are on a 256GB device, and have ~179 GB free after the cleanup, I am finding it hard to believe this was justified.

After sending some more sysdiagnose and reproduction cases Apple did his best to analyse and ended with the following conclusion:

Unfortunately I don’t bring good news.

It turned out that, currently in iOS 12 there is a new mechanism that will terminate long running background apps periodically as the system needs to free resources. At this time, this process is a bit too aggressive, and I am working with the relevant teams to get this to behave better.

So, at this point, I would like you to file a bug report. Explain the symptoms. And make sure you upload the sysdiagnose files along with the bug report. (I already sent yours in, but it doesn’t hurt to have the new ones as well). And let me know the bug number please.

So this means that currently in iOS 12 you app won't run endless on the background. I've filled in a bug report, the number is 45581276 and will try to keep this thread updated.

查看更多
仙女界的扛把子
3楼-- · 2019-01-30 20:47

I tried clearing out the /tmp and /Library/Caches directories when the app goes in the background without any change in behavior. I also tried the same periodically when the app processing background locations without any change as well.

查看更多
登录 后发表回答