Testing/Debugging Background Session Code

I’m trying to debug background session workflows. I read the excellent article Quinn wrote here: https://developer.apple.com/forums/thread/14855

I’m not seeing the call to exit(0) work for relaunching an app when a background URL Session completes. I’m also not getting the UIApplication.willTerminateNotification in that case.

I am testing on an actual device and not hooked up to the debugger.

Has anything changed since that article was published? Are there new tips for debugging background URLSession relaunch workflows?

Answered by rolson in 762755022

Actually, my logging wasn't working as I thought it was. I'm still not seeing UIApplication.willTerminateNotification which might be intended, but I am seeing the relaunch work with exit now that I've fixed the logging.

Note that Quinn is OOO right now and I will let him properly follow up here, but in the meantime, calling exit here is just a testing strategy and not documented as an officially supported workflow. So it does not surprise me that things may have moved around here.

Having said that, if you are doing long running tests capturing logs in the background without exit, are you able to see you app get launched at all for background sessions? Does this behavior change at all if you device is connected to power or via Wi-Fi etc. For more on this see Background execution demystified.

Accepted Answer

Actually, my logging wasn't working as I thought it was. I'm still not seeing UIApplication.willTerminateNotification which might be intended, but I am seeing the relaunch work with exit now that I've fixed the logging.

Testing/Debugging Background Session Code
 
 
Q