swift|swift 学习笔记 2019-04-04
MACOS 系统定位服务
Privacy - Location Always Usage Description - 描述
Privacy - Location When In Use Usage Description - 描述
lazy var locationManager:CLLocationManager = {
let locationManager = CLLocationManager()
locationManager.delegate = DMLocation.shared
return locationManager
}()
func getSunCalc(_ block: @escaping FKBlock1){
if CLLocationManager.locationServicesEnabled() {
switch CLLocationManager.authorizationStatus() {
case .restricted:
block("您无权使用位置服务.")
case .denied:
block("您拒绝使用位置服务的权限,请在“首选项”中启用它。")
case .notDetermined:
locationManager.startUpdatingLocation()
default:
block("您无权使用位置服务.")
}
}else{
}
}
【swift|swift 学习笔记 2019-04-04】extension DMLocation : CLLocationManagerDelegate{
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
switch status {
case CLAuthorizationStatus.notDetermined:
print("LocationManager授权状态未确定。 (用户尚未选择)")
case CLAuthorizationStatus.authorized:
print("我们现在已获得locationServices的授权")
locationManager.startUpdatingLocation()
//case CLAuthorizationStatus.authorizedAlways:
case CLAuthorizationStatus.denied:
print("LocationManager:我们现在被明确拒绝了")
//requestWhenInUseAuthorization
locationManager.stopUpdatingLocation()
case CLAuthorizationStatus.restricted:
print("LocationManager我们现在受限制了! (未经授权 - 可能是由于家长控制......)")
locationManager.stopUpdatingLocation()
default: break
}}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let lt = locations.last {
loaction = lt
locationManager.stopUpdatingLocation()
block(lt)
}
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
block("无法获取定位地址" + error.localizedDescription)
}
」
推荐阅读
- EffectiveObjective-C2.0|EffectiveObjective-C2.0 笔记 - 第二部分
- 由浅入深理解AOP
- 继续努力,自主学习家庭Day135(20181015)
- python学习之|python学习之 实现QQ自动发送消息
- Android中的AES加密-下
- 一起来学习C语言的字符串转换函数
- 定制一套英文学习方案
- 漫画初学者如何学习漫画背景的透视画法(这篇教程请收藏好了!)
- 《深度倾听》第5天──「RIA学习力」便签输出第16期
- 如何更好的去学习