ios如何获取位置权限

时间:2023-03-09 06:00:45
ios如何获取位置权限

 获取当前位置需要改plist文件  在plist文件加入   NSLocationWhenInUseUsageDescription  字段

  /**

初始化一个管理器对象

*/

locationManager = [[CLLocationManager alloc] init];

/**

*  设置代理

*/

locationManager.delegate = self;

locationManager.desiredAccuracy = kCLLocationAccuracyBest;

/**

*  设置移动多远来获取一次请求

*/

locationManager.distanceFilter = 1000.0f;

/**

*  判断版本

*

*  @param requestWhenInUseAuthorization

*

*  @return ios7以上需要写此方法来获取当前位置

*/

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

[locationManager requestWhenInUseAuthorization];

}

/**

*  开始获取当前位置

*/

[locationManager startUpdatingLocation];