我正在尝试使用我的日历日期添加事件,如下所示:
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"Calendar";
EKEventStore *eventStore = [[EKEventStore alloc]init];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = @"Training";
event.startDate = [[NSDate alloc]init];
event.endDate = [[NSDate alloc]initWithTimeInterval:600 sinceDate:event.startDate];
//set the default calendar type
calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
// set today
today = [[NSDate alloc] initWithTimeIntervalSinceNow:1];
//set the current day to show the calendar
NSDateComponents *components = [calendar components:units fromDate:[NSDate date]];
[components setDay:1];
self.currentDate = [calendar dateFromComponents:components];
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
//[event setCalendar:<#(EKCalendar *)#>]
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
[self fillCalendar];
}
但无法在其中添加培训事件。我想,我需要用我的替换“defaultCalenderForNewEvents” [self fillCalender]
。但是,这不起作用。你能建议一下吗?谢谢。