I am having a calendar with name MyCalendar.
I have stored some events to that calendar..
I know how to delete all the events from the calendar..as below
NSDate *startDate = [NSDate date];
NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow:[[NSDate distantFuture] timeIntervalSinceReferenceDate]];
NSArray *calendarArray = [NSArray arrayWithObject:self.defaultCalendar];
NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate
endDate:endDate
calendars:calendarArray];
NSArray *events = [self.eventStore eventsMatchingPredicate:predicate];
for (EKEvent *event in events) {
NSError* err = nil;
[self.eventStore removeEvent:event span:EKSpanFutureEvents commit:YES error:&err];
}
But when user deleted my app from device. How can I delete all the events related to Calendar MyCalendar.
As unnecessary some events of the deleted app still exists at device calendar.
It is worst to keep events related to My App if user don't want to use My App..
Any Ideas & Suggestions are appreciated..Is it possible?
Thanks in Advance..
It is pretty straightforward that we don't have any control to do some action when user is going to delete application from iPhone. May be you can provide Delete All Events
option inside application to notify user with proper massage. i think user at least single time used your application before deleting. so i think if he/she has proper idea of how this app is working then defiantly they can delete app events from application and then deleting app.
Actually we don't have any option that why i would suggest you this one. what so amount of user taking advantage of this option will helpful for them.
Actually weather apple handle such functionality or not it up to them. because some time events is not just related to app like Adding birthday
event from facebook is not just related to facebook. user need that reminder even though facebook app is deleted. so i think apple need to figure out certain solution from handling such situation.
Hope this help you.
I also don't think this is possible. And I would also think that there may had been countless radars requesting it during the years.
I think the problem is the way you store the events. If they are just related to your app, then you should store them in app, and they are only accessible in the app, and deleted when the app is deleted.
If you store them to device Calendar, then I see your app just as a manager of calendar events. Not your app events, but the USER events. He can use your app to manage them, or another app. If they are in the user Calendar, they are probably saved on cloud too, and he can manage them from the mac too.
If they would allow the functionality that you want, what would stop you from being destructive and delete all the events in the user Calendar, as a revenge because it deletes your app?
An iOS application doesn't receive any callbacks when it is about to be uninstalled, so it's not possible to do what you want.
See this question Detect iOS application about to delete?