当我的应用程序第一次尝试在iOS 8上访问摄像头时,会向用户显示摄像头权限对话框,非常类似于iOS 7中用于麦克风访问的麦克风.
在iOS 7中,可以事先调用麦克风权限对话框,并查看是否已授予权限(例如,请参阅此问题).是否有类似的方法来调用iOS 8中的相机权限对话框?可以将对话组合用于麦克风和摄像机访问权限吗?
如果用户拒绝相机访问,我将显示一个带有取消和设置按钮的警报以显示它。但代码不起作用。
@IBAction func ProfileImageButton(_ sender: UIButton) {
print("profile image Button is pressed")
let imagePickerController = UIImagePickerController()
imagePickerController.delegate = self
profileimgbool = true
let actionSheet = UIAlertController(title: "Photo Source", message: "choose a Source", preferredStyle: .actionSheet)
actionSheet.addAction(UIAlertAction(title: "Camera", style: .default, handler: {(action:UIAlertAction) in imagePickerController.sourceType = .camera
self.present(imagePickerController, animated: true, completion: nil)
}))
actionSheet.addAction(UIAlertAction(title: "Photo Library", style: .default, handler: {(action:UIAlertAction) in imagePickerController.sourceType = .photoLibrary
self.present(imagePickerController, animated: true, completion: nil)}))
actionSheet.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
self.present(actionSheet, animated: true, completion: nil)
}
func checkCameraPermission() …Run Code Online (Sandbox Code Playgroud)