iOS:为什么“启用位置服务”警报在启动时显示两次?

当我禁用位置服务时,此警报显示两次。 第一次没有显示位置pipe理器目的属性。 紧接着(在第一次提醒button被触摸之前),它再次显示,这次包括目的属性。

当第二个警报解除时,第一个警报仍然存在。

这有点烦人,我希望它会让用户感到困惑。

我可以做些什么只显示一次,目的属性?

我有一个地图控制器对象和在我的应用程序委托中实例化的位置pipe理器对象。

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

但是,在位置pipe理器在此代码中实例化之前,位置pipe理器目的属性不会被设置:

 - (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行被执行时显示第二个警报。 我将不得不做更多的testing来精确地缩小它,但是我认为我现在正走在正确的轨道上。