I am implementing the ability to add and delete user-created events from the iOS Calendar from within my app. I have coded the request for permission to access Calendar for when the user creates an event, and it's working great. I save the event on a server, and I allow them to later delete the event, and when that occurs I delete the event from the Calendar as well. It is possible someone could create an event outside of this app, open the app, then delete their appointment that is fetched from the server. There is no event stored in Calendar in this case, yet it still needs to look to see if one exists to try to delete it, and it fails because I did not ask for the user's permission to get access to the Calendar in this case.
But I don't want to ask the user for permission when deleting because the user has no idea why the app would want access to the Calendar because they never knew it could save the appointment to the Calendar - they created it on the website, and there is no reason they should grant it at that point in time because it's going to do nothing anyways.
Therefore my question is, is it possible to determine if your app currently has access to the Calendar without making a request which will result in an automatic alert being displayed to the user in the case where permission is not granted - see request code below? I simply want to search for the event to try to delete it only if I already have access to the Calendar, and if I don't, I won't try to delete anything.
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted) {
//already have access or user tapped on Allow in popup
}
...
You can use [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent]
You need to check if this method returns EKAuthorizationStatusAuthorized
to conclude that your app currently has access to the Calendar for given entity type.
More can be found in class refence here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With