简体   繁体   English

将事件添加到iOS中的生日日历

[英]Add event to Birthday calendar in iOS

I wrote this code but it doesn't work, can you help me please? 我写了这段代码,但是没有用,请您能帮我吗? I'm stuck on it for last 2 hours. 我坚持了最后两个小时。

- (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];
}

生日日历可能是只读的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM