根据苹果标准,我们需要请求许可才能访问用户摄像头。因此,我已经成功地集成了相机,并且在iOS 11中运行良好。但是目前我正在测试相机功能,发现如果用户允许一次相机访问,则在重新安装(从应用商店)后,同一应用程序将不会再次请求许可。
所以我的问题是,iOS 12的行为是否已更改,或者我们需要进行某些设置,以便每次用户尝试安装新应用时都要求请求许可?
谢谢。
所以我的问题是,iOS 12的行为是否已更改,或者我们需要进行某些设置,以便每次用户尝试安装新应用时都要求请求许可?
谢谢。
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)
}