ioscllocationmanagerios12ios-background-mode

iOS 12 terminates apps in the background for no reason


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:


Solution

  • Updated answer:

    Apple fixed this bug in iOS 12.2 beta 2 (16E5191d)

    Original analyse and bug detection:

    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.