matar
matar

Reputation: 137

swift ios 9 app not in Settings

I had swift camera code that worked on ios 8 and xcode 6. I called AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo) but my application does not show up in Settings -> privacy -> Camera (but other apps show up) camera

After updating to ios 9 and xcode 7 Can't get camera permission work. I searched 2 days on google and stackoverflow.


problem

I imported AVFoundation and called AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo) always get AVAuthorizationStatus.Denied

  1. my application does not show up in Settings -> privacy -> Camera
  2. Camera is black
  3. requestAccessForMediaType does not open popup
  4. authorizationStatusForMediaType is always Denied

Main problem is No 1. I think if I can get my app on Settings -> privacy -> Camera then other problems are solved.

thigns I tried



my code

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
                    }
                }
            });
        }

Upvotes: 1

Views: 2259

Answers (1)

longbow
longbow

Reputation: 1623

You need to set a new pair of Info.plist values, same as the String for Location Services would be in iOS8:

Just set your description string for those.enter image description here

Upvotes: 0

Related Questions