ios地图定位学习

官网的教程,
第一步:

The value for the UIRequiredDeviceCapabilities is an array of strings indicating the features that your app requires. Two strings are relevant to location services:

  • Include the location-services string if you require location services in general.
  • Include the gps string if your app requires the accuracy offered only by GPS hardware.

在info.list中的required device capabilities中添加location-services和gps字符串

第二步:

在h文件中输入:

@property(strong, nonatomic)CLLocationManager *locationManager;

在.m文件中输入:
if (_locationManager == nil) {
        _locationManager = [[CLLocationManager alloc] init];
    }
    _locationManager.delegate = self;
    _locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [_locationManager requestAlwaysAuthorization];
    [_locationManager startUpdatingLocation];
第三步:
实现CLLocationManagerDelegate代理

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations

此方法是在startUpdatingLocation方法执行后,立即执行的。
但在ios8下,并没有执行代理里面的方法。查阅了资料之后,发现ios8里面需要在info.list中添加key

NSLocationWhenInUseDescription,允许在前台获取GPS的描述
NSLocationAlwaysUsageDescription,允许在后台获取GPS的描述

然后在xcode的开发者文档中得到了验证。在Cocoa Keys中,有下面说明。

你可能感兴趣的:(iOS学习)