iOS开发

iOS 8.0 以后的版本使用CLLocationManager

2015-09-01  本文已影响249人  _lijinglong

在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的代理方法将不执行。

上一篇下一篇

猜你喜欢

热点阅读