iOS8 CoreLocation 更新
想要在項(xiàng)目中使用定位,要通過以下步驟滚停。
1.在項(xiàng)目的plist文件添加新的鍵值對
NSLocationWhenInUseUsageDescription?
NSLocationAlwaysUsageDescription
這兩個key 的value值為string類型榆芦,值為 描述獲取地理位置的原因
I enter a string like “為實(shí)現(xiàn)上班打卡功能柄粹,我們需要獲取地理位置”
2. 在類的頭部引用CoreLocation 類
@import CoreLocation;
3.添加CoreLocation實(shí)例
//添加實(shí)例
_locationManeger = [[CLLocationManager alloc] init];
//設(shè)置代理
_locationManeger.delegate = self;
//詢問用戶喘鸟,獲得權(quán)限。會有一個彈窗驻右,詢問用戶是否允許app獲取當(dāng)前地理位置
[_locationManeger requestWhenInUseAuthorization];
實(shí)現(xiàn)delegate方法
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray*)locations
{
NSLog(@"location = %@",[locations lastObject]);
}