【发布时间】:2018-11-01 12:31:09
【问题描述】:
如果不允许相机访问,我会将用户重定向到“设置”,并且当相机权限更改时,用户个人资料页面会关闭。
- 点击转到设置选项以更改权限设置
- 相机权限值更改后
- 点击状态栏上的上一个应用按钮 (?) 时
- 当前
UIViewController关闭,它转到以前的UIViewController,即rootViewController
如何预防这种情况?
【问题讨论】:
标签: ios swift permissions camera
如果不允许相机访问,我会将用户重定向到“设置”,并且当相机权限更改时,用户个人资料页面会关闭。
UIViewController 关闭,它转到以前的UIViewController,即rootViewController如何预防这种情况?
【问题讨论】:
标签: ios swift permissions camera
斯威夫特 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)
}
【讨论】: