[英]iOS: Why does “Turn on Location Services” alert show twice upon startup?
禁用位置服務后,此警報會顯示兩次。 第一次沒有顯示位置管理器用途屬性。 此后立即(在觸摸第一個警報按鈕之前),它再次顯示,這次包含了target屬性。
當關閉第二個警報時,第一個警報仍然存在。
這有點煩人,我希望它會使用戶感到困惑。
我應該怎么做才能只顯示一次目的屬性?
我的應用程序委托中同時實例化了地圖控制器對象和位置管理器對象。
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
執行代碼,我看到在執行showUserLocation
行時顯示了第二個警報。 我必須做更多測試才能精確縮小范圍,但我認為我現在處在正確的軌道上。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.