How does iOS know which location manager delegate should trigger a region’s monitoring while the application is running?

I could be confusing how the monitoring of the region works, but this is what I still have:

I register a region for monitoring through my location manager, which is implemented in a singleton class, this singleton is also set as a delegate of the location manager, so the implemented method is called.

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region 

This works fully as expected, if the application is active or paused, this method is called. This also makes sense because the class is already loaded and when the region introduces the event, iOS sends it even to my application, which calls the location manager that registered (it may have a link to it), and in turn it calls any delegate (so how the class is ready and loaded).

The problem is what happens when the application was killed? Is this the first run in the background? How does iOS know which delegate method to call, and if it is already loaded?

+6
source share
1 answer

When your application has been killed and starts to update the location, there is no delegate of the location manager yet, and as such there are no notifications sent to that delegate. The system cannot know which of your classes should be used as the delegate of the location manager or how to instantiate it.

Instead, your application:didFinishLaunchingWithOptions: is called as usual, but the UIApplicationLaunchOptionsLocationKey set in the parameter dictionary. This tells your application that you need to instantiate the location manager and set its delegation. Only after that the delegate is called with the update area.

+7
source

Source: https://habr.com/ru/post/950229/


All Articles