swift ios 9 app不在“设置”中

时间:2015-11-23 08:02:58

标签: ios xcode swift ios9 xcode7

我有快速的相机代码,适用于ios 8和xcode 6。 我调用了AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo),但我的应用程序没有显示在Settings -> privacy -> Camera中 (但其他应用程序显示) camera

更新到ios 9和xcode 7后无法获得相机权限。 我在google和stackoverflow上搜索了2天。

问题

我导入了AVFoundation并调用了AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo),总是得到AVAuthorizationStatus.Denied

  1. 我的应用程序未显示在“设置”中 - >隐私 - >相机
  2. 相机是黑色的
  3. requestAccessForMediaType无法打开弹出窗口
  4. authorizationStatusForMediaType始终被拒绝
  5. 主要问题是否1.我想如果我可以在设置上获取我的应用程序 - >隐私 - >相机然后解决其他问题。

    我试过了

    • UIImagePickerController的子类
    • 删除并重新安装了我的应用
    • 更改了套件ID
    • 将iphone日期更改为3天
    • 在主线程中调用requestAccessForMediaType
    • Xcode 7
    • ios 9.0 9.1
    • iphone 5,5s,6
    • swift 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
                        }
                    }
                });
            }
    

1 个答案:

答案 0 :(得分:0)

您需要设置一对新的Info.plist值,与位置服务的字符串在iOS8中相同:

只需为这些设置您的说明字符串。enter image description here