I have a view controller, in which I access the eventstore.
I am not sure when in the view controller I should request permission to access?
I currently request permission in viewDidLoad
.
But, what happens, if the user puts the app in the background, forgets it for a while, revokes access permission in the system settings, and finally comes back to my app. viewDidLoad
is not called then...
As a best practice, shall I request permission in viewWillAppear
, too?
I'd suggest a third alternative: Instead of viewDidLoad
or viewDidAppear
, I'd ask only when the app actually requires access to the event store, and not before. If you do it when the view first appears, the user's reaction might be "oh, I can't imagine why this app needs access, so I'll deny it". But if they initiate some action on their part which clearly requires access to the event store, that's a great time to ask permission, because the reaction will be "oh, of course I do."