iOS 8.0 CLLocationManager 定位 不响应

发布时间:2020-07-16 15:48:06 作者:xx541100047
来源:网络 阅读:1032
if ([CLLocationManager locationServicesEnabled]) {
        
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
        // As of iOS 8, apps must explicitly request location services permissions. INTULocationManager supports both levels, "Always" and "When In Use".
        // INTULocationManager determines which level of permissions to request based on which description key is present in your app's Info.plist
        // If you provide values for both description keys, the more permissive "Always" level is requested.
        if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1 && [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
            BOOL hasAlwaysKey = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"] != nil;
            BOOL hasWhenInUseKey = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"] != nil;
            if (hasAlwaysKey) {
                [self.m_locationManager requestAlwaysAuthorization];
            } else if (hasWhenInUseKey) {
                [self.m_locationManager requestWhenInUseAuthorization];
            } else {
                // At least one of the keys NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription MUST be present in the Info.plist file to use location services on iOS 8+.
                NSAssert(hasAlwaysKey || hasWhenInUseKey, @"To use location services in iOS 8+, your Info.plist must provide a value for either NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription.");
            }
        }
#endif /* __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1 */
        
        [self.m_locationManager startUpdatingLocation];

上述代码添加在

[self.m_locationManager startUpdatingLocation];


之前,

除了上述代码,还需要在info.plist中添加:

<key>NSLocationWhenInUseUsageDescription</key>

<string>这里是授权弹出框描述文字</string>

    

<key>NSLocationAlwaysUsageDescription</key>

<string>这里是授权弹出框描述文字</string>


推荐阅读:
  1. AirFlow 常见问题
  2. SID Filtering中文版bug

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ios8 ios cllocationm age ios 8

上一篇:c语言函数由哪几部分组成

下一篇:TypeScript中引用资源文件后提示找不到怎么办

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》