0
 EKEventStore *eventDB = [[EKEventStore alloc] init];
 EKEvent *myEvent  = [EKEvent eventWithEventStore:eventDB];
 NSString *trimmedString = [[arrDateList objectAtIndex:i] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
 myEvent.title     = [d valueForKey:@"garden_name"];
 myEvent.startDate = [dateFormatter dateFromString:trimmedString];
 myEvent.endDate   = [dateFormatter dateFromString:trimmedString];
 myEvent.allDay = TRUE;

 [myEvent setCalendar:[eventDB defaultCalendarForNewEvents]];
 NSError *err;
 [eventDB saveEvent:myEvent span:EKSpanThisEvent error:&err];

上記のコード行を使用していますが、イベントをカレンダーに保存できません...コード行に間違いがあるところを助けてください....ありがとう、Rahul Virja

4

1 に答える 1

0

このコードを試すことができます。

NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@ "yyyy-MM-dd HH:mm a"]; NSDate * date = [dateFormatter dateFromString:[taskDetails taskStartDateTime]];

デバッグの場合

    NSLog(@"here is the task start %@",[taskDetails taskStartDateTime]);

endif

    NSDate *end = [dateFormatter dateFromString:[taskDetails taskEndDateTime]];
    [dateFormatter release];
    EKEventStore *eventStore = [[EKEventStore alloc] init];
    EKEvent *event = [EKEvent eventWithEventStore:eventStore];
    event.title = [taskDetails taskGottaDo];   
    event.startDate = date;
    event.endDate = end;
    EKAlarm *reminder = [EKAlarm alarmWithRelativeOffset:-6*60*60];
    [event addAlarm:reminder];
    [event setCalendar:[eventStore defaultCalendarForNewEvents]];

    NSTimeInterval alarmOffset = -1*60;//1 hour
    EKAlarm *alarm = [EKAlarm alarmWithRelativeOffset:alarmOffset];

    [event addAlarm:alarm];
    [eventStore release];

    NSError *err;
    BOOL saved = [eventStore saveEvent:event span:EKSpanThisEvent error:&err];

   // NSLog(@"here is the error %@",[eventStore saveEvent:event span:EKSpanThisEvent error:&err]);
    if (saved == YES)
    {
        UIAlertView *alertView = [[UIAlertView alloc]
                                  initWithTitle:@""
                                  message:@"Saved to calendar"
                                  delegate:nil
                                  cancelButtonTitle:@"Right On!" otherButtonTitles:nil] ;
        [alertView show];   
        [alertView release];
    }
于 2012-07-31T14:33:56.690 に答える