When I have location services disabled, this alert shows up twice. The first time is without the location manager purpose property displayed. Immediately after that (before
I had both a map controller object and a location manager object instantiated in my app delegate.
mapController = [[[MapController alloc] initWithFrame:CGRectMake(0, 0, 0, 0)] retain];
[self restartLocationManager];
However, the location manager purpose property is not set until the location manager is instantiated 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 this was a clue that something in the initialization of the map was triggering the first alert.
Because I declined to turn location services on in the first alert, the map controller initialized and saw a need to show the alert. The map controller initialization is this (it is part of a singleton, and needs some cleanup in that regard, but ignoring that...):
- (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;
}
Stepping through the code, I saw the second alert show up when the showUserLocation
line was executed. I'll have to do a little more testing to narrow it down exactly, but I think I'm on the right track now.