ios8 CLLOcationManager 定位与ios7的对比

ios8在app进行定位的问题上,同ios7 有了一些不同,在ios7当中,只要 对CLLocationManager 类进行实例化,即:

    self.locationManager = [[CLLocationManager alloc] init];
    [self.locationManager setDelegate:self];
    [self.locationManager startUpdatingLocation];

在ios8当中,需要在工程的info.plist文件中添加NSLocationWhenInUseUsageDescription和NSLocationAlwaysUsageDescription两个键值,对应的变量设为YES

同时在实例化时:

  self.locationManager = [[CLLocationManager alloc] init];
    [self.locationManager setDelegate:self];
      [self.locationManager requestAlwaysAuthorization];
    [self.locationManager startUpdatingLocation];

添加

      [self.locationManager requestAlwaysAuthorization];


这样就可以在ios8当中进行系统定位了

delegate 需要添加的方法还是:

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation;

你可能感兴趣的:(IOS)