iOS地图

iOS iOS9.0 的CoreLocation定位

2015-11-12  本文已影响3988人  iOS_成才录

一、简介

@property(assign,nonatomic) BOOL allowsBackgroundLocationUpdates

+ 注意:iOS9.0 可以单次请求用户位置

```objc
- (void)requestLocation  
// 成功调用,locations位置数组,元素按照时间排序
-(void)locationManager:(nonnull CLLocationManager *)manager didUpdateLocations:(nonnull NSArray<CLLocation *> *)locations 
// 失败调用
-(void)locationManager:(nonnull CLLocationManager *)manager didFailWithError:(nonnull NSError *)error 

二、实现步骤

1、 前台定位

 _locationM = [[CLLocationManager alloc] init];
   _locationM.delegate = self;
   if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) 
       {
           [_locationM requestWhenInUseAuthorization];
       }
 [_locationM startUpdatingLocation];
-(void)locationManager:(nonnull CLLocationManager *)manager didUpdateLocations:(nonnull NSArray<CLLocation *> *)locations

2、后台定位

 if ([[UIDevice currentDevice].systemVersion floatValue] >= 9.0) {
    _locationM.allowsBackgroundLocationUpdates = YES;
}
[_locationM requestAlwaysAuthorization];
上一篇 下一篇

猜你喜欢

热点阅读