gpt4 book ai didi

ios - iOS 8 中的 requestWhenInUseAuthorization 并等待用户响应

转载 作者:可可西里 更新时间:2023-11-01 17:06:32 27 4
gpt4 key购买 nike

我正在尝试使用 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;
}
}
}

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

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

最佳答案

使用委托(delegate)方法locationManager:didChangeAuthorizationStatus:在用户允许或禁止位置请求时运行您的代码。

关于ios - iOS 8 中的 requestWhenInUseAuthorization 并等待用户响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26629435/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com