IOS startMonitoringForRegion did not work in sleep mode (black screen)

I am trying to write an application in iOS for iPhone 4 using startMonitoringForRegion, which triggers a local notification every time a location delegate receives a location update.

While the phone is awake (the screen is on), the application works well, firing notifications, but when I remove the phone (the screen is black), I no longer receive notifications until I wake up the phone by pressing the "home" button

I am trying to add “Required Backgrounds” - “Application Registers for Location Updates” to info.plist, but that doesn't make sense ...

The CLLocationManager delegator is configured as AppDelegate.

What do I need to do so that location updates are logged even when the device is sleeping? Thanks in advance.

+3
source share
1 answer

Perhaps the CLLocationManager instance was released after the application was closed.

For me, I will create a singleton location manager with the CLLocationManager property and a delegate set to singleton. After that, I would call a method startMonitoringSignificantLocationChangesto make sure the application receives the location update. It will work even if the application is killed.

In case the application gets killed, I will need to create an instance of the singleton location manager in the delegate method didFinishLaunchingWithOptions:

if ([launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey]) {
    //instantiate the singleton here
    NSArray *regions = [[[[LocationManager sharedManager] locationManager] monitoredRegions] allObjects];
}

: , ?

0

All Articles