您的位置:首页 > 移动开发 > IOS开发

IOS8 IOS9 高德地图弹出是否允许定位框功能代码

2016-03-09 17:56 316 查看


第一步:在info.plist文件添加两个字段

NSLocationAlwaysUsageDescription           - >    YES

NSLocationWhenInUseUsageDescription            - > YES

第二步:

- (CLLocationManager *)locationManager

{

    

    if (!locationManager) {

        

        locationManager = [[CLLocationManager alloc]init];

        

        locationManager.delegate = (id)self;

        

        [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];

        

        [locationManager requestAlwaysAuthorization];

        

        locationManager.distanceFilter =kCLDistanceFilterNone;

        

        [locationManager startUpdatingLocation];

        

    }

    

    return locationManager;

    

}

第三步

/*用户变更了程序的定位服务状态*/

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

    

    switch (status) {

            

        casekCLAuthorizationStatusNotDetermined:

            

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

                

                [locationManager requestWhenInUseAuthorization];

                

            }

            

            break;

            

        default:

            

            break;

            

    }

    

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  高德地图 拿权限