Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sTinGe/6f1afa6eb3817c03bab8aa9f8c1d7150 to your computer and use it in GitHub Desktop.
Save sTinGe/6f1afa6eb3817c03bab8aa9f8c1d7150 to your computer and use it in GitHub Desktop.
import AVFoundation
func cameraOn() {
let status = AVCaptureDevice.authorizationStatus(for: .video)
switch status {
case .authroized:
// has alraedy approved the privacy
// open your camera(UIImagePickerController)
break
default:
// remind and request the privacy again
AVCaptureDevice.requestAccess(for: .video, completionHandler: { granted in
if granted {
// open your camera(UIImagePickerController)
} else {
// go settings to open the camera access
requestCameraAccess()
}
}
break
}
}
func requestCameraAccess() {
// remind users to open camera access in settings
//....
if let settingsUrl = URL(string: UIApplicationOpenSettingsURLString) {
if UIApplication.shared.canOpenURL(settingsUrl) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(settingsUrl, options: [:], completionHandler: { (success) in
print("Open \(settingsUrl): \(success)")
})
} else {
UIApplication.shared.openURL(settingsUrl)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment