按照苹果的标准,我们需要获得用户相机的许可。因此,我已经成功地整合了相机,而且它在iOS 11中运行良好。但目前,我正在测试相机功能,发现如果用户一次允许相机访问,即使在重新安装(从应用程序商店)之后,相同的应用程序也不会请求许可。
所以我的问题是,在iOS 12中它的行为是否发生了变化,还是每次用户试图安装新的应用程序时,我们都需要做一些设置以获得许可?
谢谢
发布于 2018-11-30 20:08:35
iOS 12.1 / Swift 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)
}
https://stackoverflow.com/questions/52622390
复制相似问题