【问题标题】:Add event to Birthday calendar in iOS在 iOS 中将事件添加到生日日历
【发布时间】:2012-11-17 11:39:17
【问题描述】:

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

【问题讨论】:

标签: iphone ios calendar add


【解决方案1】:

生日日历可能是只读的

【讨论】:

  • 或数组索引 0 处的任何内容
  • 是的,这是生日日历。所以我不能给它添加事件?
  • 检查 calendar.isSubscribed。你不能在订阅中添加东西 AFAIK
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多