ddNative CALENDAR でイベントを作成しているときに問題に直面しています。
- (void)createEventInCalendar:(NSString *)calendarType withTitle:(NSString *)eventTitle startDate:(NSString *)stDate endDate:(NSString *)endDATE withNotes:(NSString *)paramNotes addAlarm:(BOOL)alarmNeeded {
EKEventStore *eventStore = [[EKEventStore alloc] init];
/* Are there any calendars available to the event store? */
if ([eventStore.calendars count] == 0){
NSLog(@"No calendars are found.");
}
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = [NSString stringWithFormat:@"%@ with Alarm", eventTitle];
//Convert String to DATE
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:SS"];
NSDate* date1 = [dateFormat dateFromString:stDate];
NSDate* date2 = [dateFormat dateFromString:endDATE];
//get Difference betwenn 2 DATE Values
NSTimeInterval distanceBetweenDates = [date1 timeIntervalSinceDate:date2];
event.startDate = date1;
event.endDate = [date1 initWithTimeInterval:distanceBetweenDates sinceDate:event.startDate];
event.notes = paramNotes;
/* The alarm goes off 2 seconds before the event happens */
EKAlarm *alarm = [EKAlarm alarmWithRelativeOffset:-2.0f];
[event addAlarm:alarm];
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
NSLog(@"Error shows: %@", err);
//Show EVENT EDIT Screen to User.
EKEventEditViewController *controller = [[EKEventEditViewController alloc] init];
controller.eventStore = eventStore;
controller.event = event;
controller.editViewDelegate = self;
[self presentModalViewController:controller animated:YES];
}
デバッグ後: エラー Domain=EKErrorDomain Code=4 "The start date must be before before end date." UserInfo=0x223170 {NSLocalizedDescription=開始日は終了日より前でなければなりません。}
ここで、ログ: ST DATE: 2013-04-25 07:50:00 & end DATE: 2013-04-29 07:50:00
しかし、EVENT EDIT ビューには、START DATE の前に END DATE の値が表示されます。
誰もそれを解決する方法について私を導くことができますか? ありがとう。