根据苹果标准,我们需要获得访问用户摄像头的许可。所以我已经成功集成了相机,并且在iOS 11中工作正常。但目前,我正在测试相机功能,发现如果用户一次允许相机访问,即使在全新安装后(来自应用程序商店),同一个应用程序也不会请求许可)。
所以我的问题是,iOS 12 中的行为是否发生了变化,或者每次用户尝试安装新应用程序时,我们都需要进行一些设置来询问权限?
Thanks
iOS 12.1 / 斯威夫特 4.2
每次用户点击应用程序中的“相机”按钮时,您都会调用此代码。它首先请求权限,如果过去安装的设置仍然存在,则会弹出 UIAlertController,允许用户打开设备上的“设置”应用程序,并更改相机权限设置。
OnCameraOpenButtonTap()
if UIImagePickerController.isSourceTypeAvailable(.camera) {
checkCameraAccess(isAllowed: {
if $0 {
DispatchQueue.main.async {
self.presentCamera()
}
} else {
DispatchQueue.main.async {
self.presentCameraSettings()
}
}
})
}
func checkCameraAccess(isAllowed: @escaping (Bool) -> Void) {
switch AVCaptureDevice.authorizationStatus(for: .video) {
case .denied:
isAllowed(false)
case .restricted:
isAllowed(false)
case .authorized:
isAllowed(true)
case .notDetermined:
AVCaptureDevice.requestAccess(for: .video) { isAllowed($0) }
}
}
private func presentCamera() {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .camera
present(imagePicker, animated: true, completion: nil)
}
private func presentCameraSettings() {
let alert = UIAlertController.init(title: "allowCameraTitle", message: "allowCameraMessage", preferredStyle: .alert)
alert.addAction(UIAlertAction.init(title: "Cancel", style: .cancel, handler: { (_) in
}))
alert.addAction(UIAlertAction.init(title: "Settings", style: .default, handler: { (_) in
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, options: [:], completionHandler: nil)
}))
present(alert, animated: true)
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)