3
我正在嘗試使用CLLocationManager
來獲取用戶的位置。這裏是我的簡單代碼:requestWhenInUseAuthorization in iOS 8並等待,直到用戶響應
if(IS_OS_8_OR_LATER) {
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
// iOS8+
// Sending a message to avoid compile time error
[[UIApplication sharedApplication] sendAction:@selector(requestWhenInUseAuthorization)
to:self.locationManager
from:self
forEvent:nil];
CLAuthorizationStatus authorizationStatus= [CLLocationManager authorizationStatus];
if (authorizationStatus == kCLAuthorizationStatusAuthorized ||
authorizationStatus == kCLAuthorizationStatusAuthorizedAlways ||
authorizationStatus == kCLAuthorizationStatusAuthorizedWhenInUse) {
[self.locationManager startUpdatingLocation];
}else{
[self removeIndicatorView];
return;
}
}
}
我的問題是,代碼仍然執行,即使警報在頂部。我想停止執行,直到用戶在更新位置之前按下允許或拒絕。 我該怎麼做?
我不想使用延遲或計時器。