iOS 8
如果需要在iOS中始終使用定位和在當(dāng)使用應(yīng)用的時(shí)候使用定位,需要在plist文件中添加

iOS 8 缺失的文件
NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription
這兩個(gè)字段沒什么特別的意思,就是自定義提示用戶授權(quán)使用地理定位功能時(shí)的提示語。
iOS 9
設(shè)置plist文件

iOS 9 缺失的plist文件
代碼
在ViewDidLoad中設(shè)置CLLocationManager實(shí)例的屬性
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
//在應(yīng)用使用時(shí),使用定位
locationManager.requestWhenInUseAuthorization()
if #available(iOS 9.0, *) {
locationManager.allowsBackgroundLocationUpdates = true
} else {
//設(shè)置不是iOS 9.0 的情況
locationManager.requestAlwaysAuthorization()
}
//更新用戶位置
locationManager.startUpdatingLocation()
然后實(shí)現(xiàn)代理CLLocationManagerDelegate中的方法