15

My iOS app gets terminated when put in background. I get the following logs in the device console:

Background Task 160 (""), was created over 30 seconds ago. In applications running in the background, this creates a risk of termination. Remember to call UIApplication.endBackgroundTask(_:) for your task in a timely manner to avoid this.

followed by

Background task still not ended after expiration handlers were called: . This app will likely be terminated by the system. Call UIApplication.endBackgroundTask(_:) to avoid this.

and the app terminates and restarts on resuming from background

The new metric kit background exit data (iOS 14) is also reporting that BackgroundTaskAssertionTimeoutExits are killing my app

On breaking on UIApplicationEndBackgroundTaskError, I get the following backtrace:

UIApplicationEndBackgroundTaskError backtrace

I have not implemented any background tasks myself but there are some third party libraries integrated in the app that do.

What is the right way to debug this?

pkamb
  • 33,281
  • 23
  • 160
  • 191
AKK
  • 151
  • 1
  • 4
  • 1
    Could you use a process of elimination to try to determine which of the third-party libraries (if any) might be responsible? I don't know what the libraries are or how easy it would be to separate them out, but if you could try them one at a time, or add them one at a time, you might be able to narrow it down. – scg Nov 19 '20 at 07:22
  • 2
    You might try setting a symbolic breakpoint on the methods that queue background tasks (like [UIApplication beginBackgroundTaskWithName:expirationHandler]) and then run your app to see who all is adding background tasks. If you don't catch it using the obvious API, you could try `break set -r BackgroundTask` then run and disable the locations for uninteresting API calls till you hit the one that is registering this task. – Jim Ingham Nov 20 '20 at 17:56
  • @JimIngham, the device console log: Background Task 160 (""), was created over 30 seconds ago. In applications running in the background, this creates a risk of termination. Remember to call UIApplication.endBackgroundTask(:) for your task in a timely manner to avoid this. and... Background task still not ended after expiration handlers were called: . This app will likely be terminated by the system. Call UIApplication.endBackgroundTask(:) to avoid this. But it says "private" here. Is there any way to make it print the actual name instead of "private"? – AKK Nov 25 '20 at 06:13

1 Answers1

3

If you did not start any background task, and you do not perform anything most likely some of your 3rd party frameworks are causing the crash.

Update to latest version of all your dependencies, to see if the issue was fixed.

If your issue is easily reproducible, try to disable them 1 by 1 to see which is causing the crash.

After that go on the library support page and see if there are any bugs for your issue and if not open a bug.

Start with the usual suspects, Analytics, Loggers and go on.

Have a look also at this thread: App is crashing on only iOS 13 in the background mode

pkamb
  • 33,281
  • 23
  • 160
  • 191
Mihai Georgescu
  • 674
  • 8
  • 20