gpt4 book ai didi

ios - 位置服务 : LocationAlways vs LocationWhenInUse

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

这是 iOS 应用程序中的一个奇怪行为。这是与我的问题相关的代码:

初始化位置信息:

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager requestWhenInUseAuthorization];

当请求位置功能时:

if ([CLLocationManager authorizationStatus]!=kCLAuthorizationStatusAuthorized) {
// Give a message to the user: NO GPS HERE!
}

在 app.plist 中我放置了一个键:NSLocationWhenInUseUsageDescription,带有一个字符串。

由于某种我不明白的原因,它不起作用。我被告知这个应用程序不允许使用 GPS,我必须更改隐私设置,我去按照要求更改隐私设置,我回来再试一次,并收到相同的消息……。并进入无限循环。

另一方面,如果我在 app.plist 中放置一个键:NSLocationAlwaysUsageDescription,并带有一个字符串;不改变代码中的任何内容。然后我的应用程序就可以使用位置功能(LocationAlways)。虽然这比完全没有 GPS 好,但我的应用程序最终会使用 -LocationAlways- 模式,而它很乐意使用 —LocationWhenInUse- 模式。

有人遇到同样的问题并找到解决方案吗?

最佳答案

因为 kCLAuthorizationStatusAuthorized 在 iOS 8 中已弃用

文档

kCLAuthorizationStatusAuthorized This app is authorized to use location services.

Available in iOS 2.0 and later. Deprecated in iOS 8.0

看看枚举的文档,你就会知道为什么kCLAuthorizationStatusAuthorized有效

typedef enum {
kCLAuthorizationStatusNotDetermined = 0,
kCLAuthorizationStatusRestricted,
kCLAuthorizationStatusDenied,
kCLAuthorizationStatusAuthorized,
kCLAuthorizationStatusAuthorizedAlways = kCLAuthorizationStatusAuthorized,
kCLAuthorizationStatusAuthorizedWhenInUse
} CLAuthorizationStatus;

因此,如果您请求 whenInUse,请使用此 key kCLAuthorizationStatusAuthorizedWhenInUse

关于ios - 位置服务 : LocationAlways vs LocationWhenInUse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33513383/

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