IOS: Why does the “Enable Location Services” warning appear twice at startup?

When my location services are turned off, this warning appears twice. The location manager assignment property is displayed for the first time. Immediately after that (before the first warning button is pressed), it will be displayed again, this time with the target property turned on.

When the second warning is rejected, the first warning still exists.

This is a little annoying, and I expect this to confuse users.

What can I do to show it only once using the target property?

+2
source share
1 answer

I had both a map controller object and a location manager object created in my application.

mapController = [[[MapController alloc] initWithFrame:CGRectMake(0, 0, 0, 0)] retain]; [self restartLocationManager]; 

However, the destination property of the location manager is not set until a location manager is created in this code:

 - (void) restartLocationManager { if (locationManager) [locationManager release]; locationManager = [[[CLLocationManager alloc] init] retain]; locationManager.purpose = NSLocalizedString(@"Location Service Purpose", nil); locationManager.distanceFilter = kCLDistanceFilterNone; locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; [locationManager startUpdatingLocation]; } 

So, that was the key to something in the map initialization causing the first warning.

Since I refused to enable location services in the first warning, the map controller initialized and saw the need to show a warning. The initialization of the card controller is as follows (it is part of the singleton mode and needs some cleaning in this regard, but ignores this ...):

 - (id) initWithFrame:(CGRect)aFrame { @synchronized(self) { if (!theMap) { if (!self) self = [super init]; theMap = [[[MKMapView alloc] initWithFrame:aFrame] retain]; theMap.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; theMap.showsUserLocation = YES; theMap.delegate = self; } return self; } 

While executing the code, I saw that the second warning appeared when the showUserLocation line was executed. I need to do a little more tests to narrow it down for sure, but I think I'm on the right track right now.

0
source

All Articles