gpt4 book ai didi

ios - 尝试启动 MapKit 位置更新而不提示在 ios 9 中使用 objective-c 进行位置授权

转载 作者:行者123 更新时间:2023-11-29 10:23:11 25 4
gpt4 key购买 nike

我试图在 iOS 8 上使用 MapKit,但我一直收到错误:

Trying to start MapKit location updates without prompting for location authorization. Must call   
-[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager
requestAlwaysAuthorization] first.

在这里查找,我发现我必须在我的 plist 中实现 NSLocationWhenInUsageDescription,但没有任何反应,我仍然在控制台中收到该错误。我做错了什么?

最佳答案

1.- 将以下行添加到您的 info.plist

<key>NSLocationWhenInUseUsageDescription</key>
<string>The spirit of stack overflow is coders helping coders</string>

<key>NSLocationAlwaysUsageDescription</key>
<string>I have learned more on stack overflow than anything else</string>

2.- 位置授权提示:

 if ([self.locationManager  respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[self.locationManager requestAlwaysAuthorization];

3.-当用户接受时更新位置...

   - (void) locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{

if (status == kCLAuthorizationStatusAuthorizedAlways || status == kCLAuthorizationStatusAuthorizedWhenInUse) {
[self.locationManager startUpdatingLocation];

}
}

关于ios - 尝试启动 MapKit 位置更新而不提示在 ios 9 中使用 objective-c 进行位置授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33793062/

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