0

我写了这段代码,但它不起作用,你能帮我吗?我坚持了最后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];
}
4

1 回答 1

1

生日日历可能是只读的

于 2012-11-17T12:13:15.617 回答