美文网首页iOS开发
iOS 8.0 以后的版本使用CLLocationManager

iOS 8.0 以后的版本使用CLLocationManager

作者: _lijinglong | 来源:发表于2015-09-01 11:31 被阅读249次

    在iOS8以后,在app中使用CLLocationManager实现定位,需要判断用户是否授权,如果没有授权,需要用户授权才可以使用。判断是否授权的代码如下:

    if ([[UIDevice alloc].systemVersion integerValue] > 8.0) {

    if ([CLLocationManager authorizationStatus]==kCLAuthorizationStatusNotDetermined){

    [_locationManager requestWhenInUseAuthorization];

    }else if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusAuthorizedWhenInUse){

    //设置代理

    _locationManager.delegate = self;

    }

    }

    除此之外,在info.plist文件中需要加入如下两项:

    info.plist加入选项

    如果不加,CLLocationManager的代理方法将不执行。

    相关文章

      网友评论

        本文标题:iOS 8.0 以后的版本使用CLLocationManager

        本文链接:https://www.haomeiwen.com/subject/fyvhcttx.html