2014-10-29 21 views
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; 
     } 
    } 
} 

我的问题是,代码仍然执行,即使警报在顶部。我想停止执行,直到用户在更新位置之前按下允许或拒绝。 我该怎么做?

我不想使用延迟或计时器。

回答