2

No matter where I add code to check permissions for things like camera/mic/photos, the popup confirmation always kills my app or sends me back a few view controllers.

An example is as follows.

I have few view controllers in (part way through a registration process) when I have a page that deals with the permissions. Users tap a button to deal with the camera permission which uses the following code.

if AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo) !=  AVAuthorizationStatus.Authorized {
        AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo, completionHandler: { (granted :Bool) -> Void in
            if granted == true {
                // do something
            } else {
               // determine whether not determined, denied etc and do something else
            }
        });
    }

However as soon as the iOS confirmation pops up, it throws the app back 2 view controllers. In other cases (e.g. on a viewDidLoad) permission requests kill the app as soon as the choice is made.

Any ideas what am I missing in my setup or how to prevent this behaviour?

Thanks.

4

1 回答 1

1

我想你误解了我的评论,我的意思是

if AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo) !=  AVAuthorizationStatus.Authorized { // here you are checking if it's not authorized i..e  it's denied, NotDetermined or Restricted
   ....
    }
 else if if AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo) ==  AVAuthorizationStatus.Authorized
// do the something in case it's autorized

我在这里列出键 -

     <key>NSPhotoLibraryUsageDescription</key>
     <string>This app requires access to the photo library.</string>
     <key>NSCameraUsageDescription</key>
     <string>This app requires access to the camera.</string>
于 2016-10-04T16:38:34.997 回答