Question

I add reminder events using Eventkit.framework in my app but when i show the reminder events in my app it shows all the reminder events in iPhone but I only want to show the reminder events that I added.

Here is my code for adding an event using modal view controller

EKEventEditViewController *addController = [[EKEventEditViewController alloc] initWithNibName:nil bundle:nil];
EKEvent * eve = [EKEvent eventWithEventStore:self.eventStore];

addController.eventStore = self.eventStore;
addController.event = eve;
[self presentModalViewController:addController animated:YES]; 

here is the code to retrive reminder events

self.eventStore = [[EKEventStore alloc] init];
self.eventsList = [[NSMutableArray alloc] initWithArray:0];

self.defaultCalendar = [self.eventStore defaultCalendarForNewEvents];
self.navigationController.delegate = self;
[self.eventsList addObjectsFromArray:[self fetchEventsForToday]];

fetch event method

- (NSArray *)fetchEventsForToday {

    NSDate *startDate = [NSDate date];
    NSDate *endDate = [NSDate dateWithTimeIntervalSinceNow:86400];

    NSArray *calendarArray = [NSArray arrayWithObject:defaultCalendar];

    NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate endDate:endDate
                                                                    calendars:calendarArray];

    NSArray *events = [self.eventStore eventsMatchingPredicate:predicate];
    return events;
}
Was it helpful?

Solution

Every event has the eventIdentifier property, a unique identifying string for every event. When your app adds events, it can store the eventIdentifiers in its application data and then load that list at every launch. You can make sure the events haven't been deleted by making sure that [self.eventStore eventWithIdentifier:identifier]; returns a valid EKEvent. When you want to display a list of events that your app added, you can just get the events that match the identifiers that you have saved. Because the identifiers will never be reused, this system wont be affected by users who add and delete events outside of your app.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top