1
我有在iOS 8和Xcode的6 我叫AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo),但我的應用程序中顯示不出來的工作迅速相機代碼Settings -> privacy -> Camera (但其他應用程式) 迅速IOS 9應用程序沒有設置
更新到ios 9和xcode 7後無法獲取攝像頭權限。 我在谷歌和stackoverflow上搜索了2天。
問題
我進口AVFoundation,並呼籲AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo)總是得到AVAuthorizationStatus.Denied
- 我的應用程序不能在設置顯示 - >隱私 - >相機
- 相機是黑色的
- requestAccessForMedia類型不開彈出
- authorizationStatusForMediaType總是拒絕
主要問題是否1.我想,如果我能得到我的應用程序設置 - >隱私 - >相機那麼其他問題都解決了。
thigns我試圖
- 子類的UIImagePickerController
- 刪除並重新安裝我的應用程序
- 在更改包ID在未來
- 稱爲requestAccessForMediaType
- 更改iphone日至3天主線程
- 的Xcode 7
- IOS 9.0 9.1
- iphone 5,5S,6
- 迅速2.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
}
}
});
}
非常感謝你,我沒有嘗試過那個。我將下面的代碼添加到info.plist。但仍然沒有出現在隱私設置 ' NSCameraUsageDescription \t 相機 \t NSPhotoLibraryUsageDescription \t 照片 ' 結果在啓動AVAuthorizationStatus.NotDetermined。 然後當我請求權限與requestAccessForMediaType 結果是AVAuthorizationStatus.Denied –
matar
謝謝你指着我正確的方向。 當我將這些鍵添加到我的項目中時,它無法正常工作。 所以我創建了新項目,並將這些密鑰和複製的info.plist文件複製到我的項目中,並且工作正常。 – matar