gpt4 book ai didi

ios - requestWhenInUseAuthorization 失败时发出通知

转载 作者:行者123 更新时间:2023-11-29 01:16:30 24 4
gpt4 key购买 nike

我正在尝试创建一种 locationServices 权限身份验证,只有当应用程序具有 locationServices 权限时,您才能使用该应用程序。因此,如果用户拒绝 locationManager.requestWhenInUseAuthorization(),它应该向 viewController 提供有关此信息的信息。但是,如果用户拒绝,我似乎无法收到通知。最好的解决方案是什么?还是应该考虑以其他方式实现?

func determinePermission() {

switch CLLocationManager.authorizationStatus() {

case .AuthorizedAlways, .AuthorizedWhenInUse:
if CLLocationManager.locationServicesEnabled() {

}

case .NotDetermined:
locationManager.requestWhenInUseAuthorization()

case .Restricted, .Denied:

let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc: UIViewController = storyboard.instantiateViewControllerWithIdentifier("PermissionController") as! PermissionViewController

self.parentViewController!.tabBarController!.presentViewController(vc, animated: true, completion: nil)

}
}

最佳答案

实现 CLLocationManagerDelegate 协议(protocol)。CLLocationManagerDelegatelocationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) 方法,在授权状态改变时被调用.

func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
switch status {
case .AuthorizedWhenInUse:

case .AuthorizedAlways:
// you have access
break

case .Denied :

default:
// you don't have access. add your code here to present new view
break
}
}

关于ios - requestWhenInUseAuthorization 失败时发出通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35118276/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com