Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 15th, 2012  |  syntax: None  |  size: 1.46 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // Surely there has to be a way to hook into the create....({}) call ?
  2. -(NSDictionary *)saveEvent:(id)obj
  3. {
  4.         EKEventStore *eventStore = [[[EKEventStore alloc] init] autorelease];
  5.         EKEvent *_event = [EKEvent eventWithEventStore:eventStore];
  6.         //EKRecurrenceEnd *count = [self valueForUndefinedKey:@"recurrenceCount"];
  7.         EKRecurrenceEnd *end = [EKRecurrenceEnd recurrenceEndWithOccurrenceCount:4];
  8.        
  9.         EKRecurrenceRule *rule = [[EKRecurrenceRule alloc]
  10.                                                           initRecurrenceWithFrequency:EKRecurrenceFrequencyWeekly
  11.                                                           interval:1
  12.                                                           end:end];
  13.         _event.recurrenceRule = rule;
  14.         _event.title = [self valueForUndefinedKey:@"title"];
  15.         _event.startDate = [self valueForUndefinedKey:@"sdate"];  
  16.         _event.location = [self valueForUndefinedKey:@"location"];  
  17.         _event.endDate = [self valueForUndefinedKey:@"edate"];  
  18.     if ([self valueForUndefinedKey:@"edate"] == nil) {
  19.                 _event.endDate = [[[NSDate alloc] initWithTimeInterval:1200 sinceDate:_event.startDate] autorelease];
  20.         }
  21.         [_event setCalendar:[eventStore defaultCalendarForNewEvents]];
  22.     NSError *err = nil;
  23.     [eventStore saveEvent:_event span:EKSpanThisEvent error:&err];  
  24.         BOOL status = (err == nil) ? TRUE : FALSE;
  25.         NSString *errStr = (err != nil) ? [err localizedDescription] : @"none";
  26.        
  27.         NSDictionary *tmp = [[[NSDictionary alloc] initWithObjectsAndKeys: errStr, @"error",
  28.                                                   NUMBOOL(status), @"status",
  29.                                                   _event.eventIdentifier, @"eventId",
  30.                                                   nil] autorelease];
  31.         return tmp;
  32. }