(void)viewDidLoad {
[super viewDidLoad];//1. 创建位置管理器
_mgr = [CLLocationManager new];//2. 用户授权
//当使用时授权
/*
注意配置plist数据:
Privacy - Location When In Use Usage Description
Privacy - Location Always Usage Description
*/
[_mgr requestWhenInUseAuthorization];//3. 设置代理(为了获取定位的数据, 需要中代理方法中获取)
_mgr.delegate = self;//4. 开始定位
[_mgr startUpdatingLocation];
}
// CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager )manager didUpdateLocations:(NSArray