iOS 8中的requestWhenInUseAuthorization方法,等待用户响应

4
我将尝试使用CLLocationManager获取用户位置。以下是我的简单代码:
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;
        }
    }
}

我的问题是,即使弹出提示框,代码仍然继续执行。我想在更新位置之前停止执行,直到用户点击允许或拒绝。

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

1个回答

7

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接