我将在日历中添加一个事件。
我的代码是正确的,但我需要来自 Datepicker 的日期和时间。
如何从 datepicker 为以下代码设置日期和时间:
EKEventStore *es = [[EKEventStore alloc] init];
[es requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
/* This code will run when uses has made his/her choice */
EKEvent *myEvent = [EKEvent eventWithEventStore:es];
myEvent.title = @"New Event";
myEvent.startDate = [NSDate date]; // I need to set date from Datepicker
NSTimeInterval interval = 60*+5; // I need to set time from Datepicker
EKAlarm *alarm = [EKAlarm alarmWithRelativeOffset:interval];
[myEvent addAlarm:alarm];
myEvent.endDate = [[NSDate date] initWithTimeInterval:600 sinceDate:myEvent.startDate];
[myEvent setCalendar:[es defaultCalendarForNewEvents]];
NSError *err;
[es saveEvent:myEvent span:EKSpanThisEvent error:&err];
}];
您可以看到我将设置日期和时间的评论。
谢谢。