Created
May 27, 2018 07:58
-
-
Save sTinGe/6f1afa6eb3817c03bab8aa9f8c1d7150 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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