Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVCaptureDevice.requestAccessForMediaType never pops up window and always return false

Tags:

swift

swift2

I have some problem asking user for permission about camera. The authorizationStatus is always NotDetermined. When I tried to ask user for permission, AVCaptureDevice.requestAccessForMediaType never pops up a dialog and granted always returns false. I also can't find my app in settings - privacy - camera.

Can anyone help me with that? really appreciated

let availableCameraDevices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo)
    for device in availableCameraDevices{

        if (device.position == .Back){
            backCameraDevice = device
        }else{
            if (device.position == .Front){
                frontCameraDevice = device
            }
        }
    }

    let authorizationStatus = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo)
    switch authorizationStatus {
    case .NotDetermined:
        // permission dialog not yet presented, request authorization
        AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo,
            completionHandler: { (granted:Bool) -> Void in
                if (granted == false) {
                    print(granted)
                }
                else {
                    print(granted)
                }
        })
    case .Authorized: break
        // go ahead
    case .Denied, .Restricted: break
        // the user explicitly denied camera usage or is not allowed to access the camera devices
    }
like image 997
Jiatan Li Avatar asked Jan 09 '16 17:01

Jiatan Li


1 Answers

Problem solved. It seems that when we upgrade from iOS 8 to iOS 9, it has a new property in info.plist which is Bundle Display Name. Set the name to your product name if it is null, or the system will never know what app is asking for a permission

like image 54
Jiatan Li Avatar answered Oct 19 '22 05:10

Jiatan Li