如何在 iOS 8 的 CLLocationManager 中启用"When app in use"



我刚刚意识到iOS 8中定位服务有一个新的隐私选项,允许用户选择"应用程序使用时"作为隐私选项。

我的应用程序需要回到iOS7,我不知道如何让这个选项适用于我的应用。目前它只说"永远/永远"

我没有在代码中做任何特别的事情。使用启动定位服务

startUpdatingLocation

当在前台时,以及

startMonitoringSignificantLocationChanges

当在后台时。

我还尝试过实现

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

但无济于事。

有什么想法吗?

对于iOS 8,您必须向plist添加一个新值,NSLocationWhenUseUsageDescription或NSLocationAlwaysUsageDescription。如果希望在向用户显示警报时显示特定消息,可以将字符串设置为位置键的值。

此外,您必须添加此代码才能真正请求用户的权限,使用您在plist中使用的任何键来切换函数。

#pragma message ("iOS 8 Support for location updating")
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]){
    [self.locationManager requestWhenInUseAuthorization];
}

更多信息https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/

最新更新