我在我的应用委托中实例化了一个地图控制器对象和一个位置管理器对象。
mapController = [[[MapController alloc] initWithFrame:CGRectMake(0, 0, 0, 0)] retain];
[self restartLocationManager];
但是,在此代码中实例化位置管理器之前,不会设置位置管理器用途属性:
- (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];
}
所以这是地图初始化中的某些东西触发了第一个警报的线索。
因为我拒绝在第一个警报中打开位置服务,所以地图控制器已初始化并看到需要显示警报。地图控制器初始化是这样的(它是单例的一部分,在这方面需要一些清理,但忽略...):
- (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;
}
单步执行代码时,我看到在执行showUserLocation 行时出现了第二个警报。我必须做更多的测试才能准确地缩小范围,但我认为我现在走在正确的轨道上。