Est*_*ood 5 core-location cllocationmanager swift xcode6 ios8
我的Swift应用程序要求允许通过CLLocationManager访问当前位置.当用户点击"不允许"时,如何显示警告消息?
你想看看
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus)
Run Code Online (Sandbox Code Playgroud)
和
CLLocationManager.authorizationStatus()
Run Code Online (Sandbox Code Playgroud)
第一个是在用户更改授权状态时调用的,第二个是允许您随时确定当前状态.
然后,显示消息,例如:
let alert = UIAlertController(title: "Your title", message: "GPS access is restricted. In order to use tracking, please enable GPS in the Settigs app under Privacy, Location Services.", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Go to Settings now", style: UIAlertActionStyle.Default, handler: { (alert: UIAlertAction!) in
print("")
UIApplication.sharedApplication().openURL(NSURL(string:UIApplicationOpenSettingsURLString)!)
}))
Run Code Online (Sandbox Code Playgroud)
上面的代码显示警报,并允许用户直接进入设置以启用位置.
| 归档时间: |
|
| 查看次数: |
4108 次 |
| 最近记录: |