我有快速的相机代码,适用于ios 8和xcode 6。 我调用了AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo),但我的应用程序没有显示在Settings -> privacy -> Camera中 (但其他应用程序显示)
更新到ios 9和xcode 7后无法获得相机权限。 我在google和stackoverflow上搜索了2天。
问题
我导入了AVFoundation并调用了AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo),总是得到AVAuthorizationStatus.Denied
主要问题是否1.我想如果我可以在设置上获取我的应用程序 - >隐私 - >相机然后解决其他问题。
我试过了
我的代码
override func viewDidLoad() {
super.viewDidLoad()
cameraView()
}
func checkCamera() {
let authStatus = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo)
switch authStatus {
case AVAuthorizationStatus.Authorized:
print("AVAuthorizationStatus.Authorized")
case AVAuthorizationStatus.Denied:
print("AVAuthorizationStatus.Denied")
case AVAuthorizationStatus.NotDetermined:
print("AVAuthorizationStatus.NotDetermined")
case AVAuthorizationStatus.Restricted:
print("AVAuthorizationStatus.Restricted")
default:
print("AVAuthorizationStatus.Default")
}
}
func cameraView(){
// session
let mySession : AVCaptureSession = AVCaptureSession()
var myDevice : AVCaptureDevice? //= AVCaptureDevice()
let myImageOutput : AVCaptureStillImageOutput = AVCaptureStillImageOutput()
let devices = AVCaptureDevice.devices()
let audioCaptureDevice = AVCaptureDevice.devicesWithMediaType(AVMediaTypeAudio)
let audioInput = (try! AVCaptureDeviceInput(device: audioCaptureDevice[0] as! AVCaptureDevice)) as AVCaptureInput
for device in devices {
if(device.position == AVCaptureDevicePosition.Back){
myDevice = device as? AVCaptureDevice
}
}
let status = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo)
print(status == AVAuthorizationStatus.Authorized)
print(status == AVAuthorizationStatus.Denied)
print(status == AVAuthorizationStatus.Restricted)
print(status.rawValue)
if status != AVAuthorizationStatus.Authorized {
AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo, completionHandler: { (granted :Bool) -> Void in
if granted == false {
// Camera not Authorized
dispatch_async(dispatch_get_main_queue()) {
print("Camera not Authorized")
self.checkCamera()
return
}
}
});
}