O'Reilly logo

iOS 5 Programming Cookbook by Vandad Nahavandipoor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

14.8. Handling Event Changed Notifications

Problem

You want to get notified in your application when the user changes the contents of the Calendar database.

Solution

Register for the EKEventStoreChangedNotification notification:

- (EKCalendar *) calDAVCalendarWithTitleContaining:(NSString *)paramDescription inEventStore:(EKEventStore *)paramEventStore{ EKCalendar *result = nil; for (EKCalendar *thisCalendar in paramEventStore.calendars){ if (thisCalendar.type == EKCalendarTypeCalDAV){ if ([thisCalendar.title rangeOfString:paramDescription].location != NSNotFound){ return thisCalendar; } } } return result; } - (void) eventsChanged:(NSNotification *)paramNotification{ NSMutableArray *invalidatedEvents = [[NSMutableArray alloc] init]; NSLog(@"Refreshing array of events..."); for (EKEvent *event in self.eventsForOneYear){ if ([event refresh] == NO){ [invalidatedEvents addObject:event]; } } if ([invalidatedEvents count] > 0){ [self.eventsForOneYear removeObjectsInArray:invalidatedEvents]; } } - (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.eventStore = [[EKEventStore alloc] init]; EKCalendar *calendar = [self calDAVCalendarWithTitleContaining:@"vandad.np@gmail.com" inEventStore:self.eventStore]; NSTimeInterval NSOneYear = 1 * 365 * 24 * 60 * 60; NSDate *startDate = [NSDate date]; NSDate *endDate = [startDate dateByAddingTimeInterval:NSOneYear]; NSArray *calendars = [[NSArray alloc] initWithObjects:calendar, nil]; NSPredicate ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required