【问题标题】:UIViewController dismiss after camera permission updated in SettingsUIViewController 在设置中更新相机权限后关闭
【发布时间】:2018-11-01 12:31:09
【问题描述】:

如果不允许相机访问,我会将用户重定向到“设置”,并且当相机权限更改时,用户个人资料页面会关闭。

  1. 点击转到设置选项以更改权限设置
  2. 相机权限值更改后
  3. 点击状态栏上的上一个应用按钮 (?) 时
  4. 当前UIViewController 关闭,它转到以前的UIViewController,即rootViewController

如何预防这种情况?

【问题讨论】:

标签: ios swift permissions camera


【解决方案1】:
【解决方案2】:

斯威夫特 4.2

如果您的应用中有表单并且您可能需要权限 更改您的应用程序,您应该存储和恢复数据。因为你的应用 权限更改后可能会重新启动(相机使用权限 示例)。

第 1 步:通过您故事板上的 Identity Inspector 将恢复 ID 添加到您的 UIViewControllers。

第 2 步:将这些方法添加到 AppDelegate

func application(_ application: UIApplication, shouldSaveApplicationState coder: NSCoder) -> Bool {
    return true
}

func application(_ application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -> Bool {
    return true
}

第 3 步:在您的 UIViewController 中覆盖这些方法。您的数据将存储在encodeRestorableState 方法中。他们将在decodeRestorableState方法中恢复。

override func encodeRestorableState(with coder: NSCoder) {
    coder.encode(self.myTextField.text ?? "", forKey: "myTextFieldRestorationKey")
    super.encodeRestorableState(with: coder)
}

override func decodeRestorableState(with coder: NSCoder) {
    if let txt = coder.decodeObject(forKey: "myTextFieldRestorationKey") as? String { self.myTextField.text = txt }
    super.decodeRestorableState(with: coder)
}

【讨论】:

    猜你喜欢
    • 2012-08-12
    • 2017-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-30
    • 1970-01-01
    • 2022-08-16
    • 2021-05-21
    相关资源
    最近更新 更多