首页 > 学院 > 开发设计 > 正文

[转载]iOS9使用CoreLocation

2019-11-14 18:13:07
字体:
来源:转载
供稿:网友

在iOS8之前,只要

#import <CoreLocation/CoreLocation.h>引入CoreLocation.framework.

@PRoperty (nonatomic, strong) CLLocationManager  *locationManager;

就可以使用位置信息。

在iOS8之后,苹果对定位进行了一些修改,其中包括定位授权的方法,CLLocationManager增加了下面的两个方法:

(1)始终允许访问位置信息

- (void)requestAlwaysAuthorization;

(2)使用应用程序期间允许访问位置数据

- (void)requestWhenInUseAuthorization;

示例如下:

self.locationManager = [[CLLocationManager alloc]init];_locationManager.delegate = self;_locationManager.desiredAccuracy = kCLLocationAccuracyBest;_locationManager.distanceFilter = 10;[_locationManager requestAlwaysAuthorization];//添加这句[_locationManager startUpdatingLocation];

ios8_location_info_plist.png

 

转载自:http://blog.devzeng.com/blog/ios8-corelocation-framework.html

 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表