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.

RobertyBob
  • 803
  • 1
  • 8
  • 20
  • how about denied ? – Misha Oct 04 '16 at 10:00
  • @Misha - I understand there are more options for the user to choose and these are dealt with if needed but irrelevant to the question I think – RobertyBob Oct 04 '16 at 12:35
  • but how will the app decide what to do in case permisiion is denied ?on another note have you added keys in plist? – Misha Oct 04 '16 at 12:47
  • @misha - it will decide what to do based on what the code says to do - in this case it doesn't really do anything but the point is that the view rolls back when the popup shows - the rest is irrelevant but I'll edit the question to avoid future confusion – RobertyBob Oct 04 '16 at 14:59
  • Irrespective of what it does if not authorised, the point is that I always authorise but the process crashes or rolls back the views, either as soon as it asks for the decision or when authorised – RobertyBob Oct 04 '16 at 15:02
  • @misha as for the plist keys - can you give me more information? I have added the key/values for the text that shows on the popup e.g., Privacy - Camera Usage Description – RobertyBob Oct 04 '16 at 15:03

1 Answers1

1

I think you misunderstood my comment, what I did meant was

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

I'm listing keys here -

     <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>
Misha
  • 685
  • 8
  • 20
  • Thanks Misha - I have the status check for determining what the state is currently and the other code (granted==true) for determining their choice on the popup - as for the keys I'm adding these as I have one for NSLocationWhenInUseUsageDescription but the camera/photos ones are in with a key 'Privacy - Camera Usage Description' (not sure where I got that key from) - will check back shortly with results – RobertyBob Oct 05 '16 at 11:18
  • it seems that I had a missing entry in info.plist for one of the descriptions which was causing it to pop to the closest navigationController (which is weird but no matter) - adding all descriptions I can think of seems to have sorted the problem – RobertyBob Oct 06 '16 at 14:14