0

My request for photo library permissions prompt is supposed to pop up as soon as the app is launched. I have set up my info.plist with the library permission. I have tried both adding/removing the requestAuthorization(_:) function in my AppDelegate.swift in various lifecycle functions.

Current output: The app launches and stays on the launchscreen. When i click on the home button the app minimizes and the permissions prompt appears(as though it was lingering in the background). On allowing permission everything launches as expected.

Desired output: The app launches and the photo library permissions prompt appears on top(as it should). On click of which everything runs as usual.

I can attach pictures if this is not descriptive enough. Also there is no pertaining code as i have removed the requestAuthorization(_:) function(cuz not required). Any tip would go a long way as I have been fiddling with this for days now trying to get this fixed. Thank you!

Samir K
  • 91
  • 2
  • 11
  • That's not the default behavior in iOS. The OS will popup - one time only - a request for permission **when** you try to access the photo library, not before. Even if you somehow manage to find a different way to do this - and Apple approves it - why do something with your app so unexpected? From a use standpoint it seems like a recipe for disaster. –  Feb 14 '19 at 23:12
  • yes i am applying the default behaviour where the prompt appears only once, but in the background @dfd. Nothing off the book – Samir K Feb 15 '19 at 17:26
  • Ok, but as pointed out, you're doing it in the background. Break it down into pieces... start with a *basic* project that in a view controller presents a simple alert. (yep, that basic.) Now start customizing it... can you present it in `AppDelegate`? How about in the background? If yes, then go back to the basics and make it the privacy popup... can you have it work in *a* `UIImagePickerController`? How about your's, assuming you may be using something else. How about in `viewDidLoad`? Somewhere in there you'll find where the OS is not behaving the way you'd like. –  Feb 16 '19 at 04:09
  • @dfd So i tried quite a few things, breaking it down to the bare bones. Turns out when i set a root viewcontroller before the photo library viewcontroller, the prompt pops up as expected up top, when navigating to it. But when the photo library viewcontroller is kept as the rootview controller then the prompt doesn't show up on top :\ – Samir K Feb 16 '19 at 21:26
  • Sounds like it was a "good exercise" with less than desired results. It also sounds like you are butting up against an iOS behavior. Hopefully you can find a "best case" way to do what you want. –  Feb 16 '19 at 21:46

1 Answers1

0

Your request call should be in the view controller (i.e. viewDidAppear), not the AppDelegate. Having the call in the app delegate is probably causing it to fire at an inappropriate time.

Hobbes the Tige
  • 3,753
  • 2
  • 22
  • 21
  • Yeah but request call is not required, as I have added the Privacy key in the info.plist file. So i removed the requestAuthCall from the code – Samir K Feb 14 '19 at 22:17