[英]iOS permission alert issue
我认为:
UIApplicationDidBecomeActiveNotification
创建一个观察者 UIButton
,其状态取决于每个权限状态,如果拒绝任何权限,它们会将用户导航到设置 授予所有权限后,它将推送其余视图的注册/输入流程中的下一个视图。
问题是:在某些设备上,从干净状态运行应用程序(已删除并重新安装应用程序)时,默认情况下将位置和通知权限设置为拒绝,就像向用户显示了被拒绝的警报一样。
我无法指出这背后的任何合理问题,除了一些过时的内部版本的剩余设置,这些剩余设置在安装新版本时不会被删除。 该视图似乎是唯一可能触发这些警报的地方。
有没有人有类似的问题,可以提出任何建议?
我建议您在要求用户使用之前尝试尝试检查位置服务和通知服务的状态。 由于如果用户要在您请求其许可时立即禁用这些设置,则他将需要转到设置并在此处启用它。 您应该尝试检测用户是否禁用了位置/通知/相机。
对于相机使用:
func accessToCamera(granted: @escaping (() -> Void)) {
if UIImagePickerController.isSourceTypeAvailable(.camera) {
let status = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeAudio)
if status == .authorized {
granted()
} else if status == .denied {
self.cameraPermissionAlert()
} else if status == .notDetermined {
AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (accessAllowed) in
if accessAllowed {
granted()
} else {
self.cameraPermissionAlert()
}
})
} else if status == .restricted {
self.cameraPermissionAlert()
}
} else {
print("Camera not available on this device")
}
}
func cameraPermissionAlert() {
let alert = UIAlertController(title: "Access to camera not available", message: "Please enable access to camera in order to use this feature", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Settings", style: .default, handler: { (action) in
if let url = URL(string: UIApplicationOpenSettingsURLString) {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil))
if let top = UIApplication.topViewController() { // This is extension to UIApplication that finds top view controller and displays it
top.present(alert, animated: true, completion: nil)
}
}
对于远程通知,您可以使用以下方式: 在iPhone上确定用户是否已启用推送通知
对于定位服务: 检查是否启用了定位服务
在这两种情况下,您都可以检测用户是否禁用了此功能,并向用户提供具有开放设置功能的警报控制器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.