【问题标题】:iOS permission alert issueiOS权限警报问题
【发布时间】:2017-08-24 01:57:41
【问题描述】:

我认为:

  • 通过调用选择器为UIApplicationDidBecomeActiveNotification 创建一个观察者
  • 依次请求用户授予以下权限:使用相机、位置和接收推送通知。
  • 视图具有三个 UIButtons,其状态取决于每个权限状态,如果任何权限被拒绝,它们会将用户导航到设置
  • 点击代表具有拒绝状态的权限的按钮会将用户导航到设置
  • 一旦隐藏每个警报,使用观察者操作,就会触发下一个警报并更新所有按钮状态以反映任何更改

一旦授予所有权限,它就会推送下一个视图以及注册/输入流程的其余部分。

问题是:在某些设备上,当从干净状态(删除并重新安装应用程序)运行应用程序时,位置和通知的权限默认设置为拒绝,就像向用户显示被拒绝的警报一样。

我无法确定这背后的任何合理问题,除了一些过时版本的剩余设置在安装新版本时不会被删除。这个视图似乎是唯一可能触发这些警报的地方。

有没有人有类似的问题可以提出任何建议?

【问题讨论】:

  • 有些权限会在 iOS 中存储 24 小时,无论您是否删除了该应用程序。您可以通过启动具有不同捆绑 ID 的应用程序或手动重置 iOS 设置中的所有权限来强制它们重新出现。
  • 我已尝试删除该应用,重置位置和隐私设置,然后重新安装该应用。同样的情况

标签: ios xcode permissions alert ios-permissions


【解决方案1】:

我建议您在要求用户使用它之前尝试检查位置服务和通知服务的状态。因为如果用户要在您请求他许可的那一刻禁用这些,他将需要转到设置并在那里启用它。您应该尝试检测用户是否禁用了位置/通知/相机。

相机使用:

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)
        }
    }

对于远程通知,您可以使用以下内容: Determine on iPhone if user has enabled push notifications

对于定位服务: Check if location services are enabled

在这两种情况下,您都可以检测用户是否禁用了此功能,并向用户提供具有开放设置功能的警报控制器。

【讨论】:

    猜你喜欢
    • 2017-07-12
    • 2015-04-11
    • 1970-01-01
    • 2012-12-18
    • 2021-02-11
    • 2018-11-18
    • 1970-01-01
    • 2018-12-03
    • 2021-06-11
    相关资源
    最近更新 更多