我写了这段代码,但它不起作用,你能帮我吗?我坚持了最后2个小时。
- (IBAction)addBirthday:(id)sender {
NSString *name = self.textField.text;
NSDate *date = [self.datePicker date];
EKEventStore *eventStore = [[EKEventStore alloc] init];
[eventStore calendarsForEntityType:EKEntityTypeEvent];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = [NSString stringWithFormat:@"%@’s Birthday", name];
event.startDate = date;
event.endDate = date;
NSArray *calendars = [eventStore
calendarsForEntityType:EKEntityTypeEvent];
NSLog(@"ARRAY: %@", [calendars objectAtIndex:0]);
[event setCalendar: [calendars objectAtIndex:0]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
}