I'm writing an application that runs in background mode that can track user (so sometimes updates location in background mode) and, by using region monitoring, informs him of nearby points. I do not use the feature of relaunching the application from region monitoring.
Currently, after getting the applicationWillTerminate:
message, I stop location updates and remove all points from region monitoring. I noticed strange behaviour of the application. The following messages (in order like below) are delivered to the application after trying to kill it in multitasking menu:
applicationWillTerminate:
applicationDidEnterBackground:
locationManager:didUpdateToLocation:fromLocation:
If I don't register background location mode for this application, it is just killed instead.
I'd like application to terminate like other applications after user kills it in the multitasking menu and not get messages from region monitoring (no points are tracked at that moment anyway). Still, I need to be able to use background location mode. The purpose is to minimize the usage of battery. What should I do to achieve that?
Also, why does the application receive applicationDidEnterBackground:
after applicationWillTerminate:
? Is it still running or not after shutting it down from multitasking menu?
In the end I tested it experimentally and checked if everything that is covered in documentation is true. It seems it is. Those are the results, that aren't fully specified in documentation:
If the application doesn't support UIBackgroundModes
like location
, it is killed (receives signal 9) after terminating it in multitasking menu (after receiving applicationWillTerminate:
).
If the application supports location
background mode, it receives applicationWillTerminate:
, applicationDidEnterBackground:
and is suspended. Before next launch of the application, it is silently terminated.
If you're monitoring a region in your application and it was terminated in multitasking menu, it will be relaunched on region events with UIApplicationLaunchOptionsLocationKey
option. If user launches the application after that, it isn't terminated but simply starts getting the applicationDidBecomeActive:
and other messages.
As expected, the application isn't draining the battery after being terminated, if you stop monitoring all regions in applicationWillTerminate:
method. Though, if you'd not stop monitoring regions and had high region monitoring accuracy set, then it is draining a lot of battery, even if terminated (since iOS is actively monitoring those points then).
Behaviour of the application with set background location mode, after termination, is actually the same, whether you monitor regions or not. Only that in first case it just won't ever get messages about entering region nor drain the battery.