简体   繁体   中英

When does applicationDidBecomeActive get called with respect to requestAccessToEntityType?

I just ran into an issue that I thought I'd share. In my iOS calendar usage, I'm making use of applicationDidBecomeActive in the app delegate to check if the users calendar settings have changed. Specifically, after getting the applicationDidBecomeActive callback, I do the following:

// self.eventStore is of type EKEventStore *
EKCalendar *cal = [self.eventStore calendarWithIdentifier: calendarIdentifier];
if (!cal) {
    // Assume we no longer have access to the users calendar; e.g., they have change their privacy settings.
}

However, I ran into an issue. (How surprising! :)). I found that applicationDidBecomeActive is also called when we do initially do requestAccessToEntityType. That is, after Apple displays their "Alert" to the user to ask if the user wants our app to have access to their calendar, our app gets a applicationDidBecomeActive callback. My only remaining question with this, now that I've figured that out is:

When requestAccessToEntityType is called, do we always get the applicationDidBecomeActive before the completion handler of requestAccessToEntityType is called?

I'm assuming this is true. It would seem very unusual to me if one my methods was called (outside of the app delegate) before the app delegate applicationDidBecomeActive method was called.

My assumption is incorrect. The requestAccessToEntityType: callback can be executed before the app delegate applicationDidBecomeActive: method is called. I just observed this in my code. I'm not 100% sure if this is always the ordering of execution.

After thinking about this more, I'm now going to code so that I don't depend on this ordering of calls or on whether or not applicationDidBecomeActive: is called when requestAccessToEntityType: is called. It seems that this behavior ( applicationDidBecomeActive: being called when requestAccessToEntityType: is called) is not specified by Apple, and could change.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM