gpt4 book ai didi

iPhone - 如何导入所有日历事件,包括事件 ID?

转载 作者:行者123 更新时间:2023-12-03 21:16:38 25 4
gpt4 key购买 nike

我正在开发一个与 iPhone 日历相关的简单应用程序。我可以将日历事件从我的应用程序添加到 iPhone 日历。保存事件后,我需要获取保存的事件 ID 。我怎样才能做到这一点。下面是保存事件的代码。

EKEventStore *eventStore = [[EKEventStore alloc] init]; 
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = @"xxx";
event.notes = @"yyy";
event.startDate = [[NSDate alloc] init];
event.endDate = [[NSDate alloc] initWithTimeInterval:600 sinceDate:event.startDate];
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];

提前致谢。

最佳答案

要保存事件,请调用此方法,并打印所有带有标识符的保存事件...

- (void)eventEditViewController:(EKEventEditViewController *)controller
didCompleteWithAction:(EKEventEditViewAction)action {

NSError *error = nil;

EKEvent *thisEvent = controller.event;

switch (action) {
case EKEventEditViewActionCanceled:
// Edit action canceled, do nothing.
break;

case EKEventEditViewActionSaved:
// When user hit "Done" button, save the newly created event to the event store,
// and reload table view.
// If the new event is being added to the default calendar, then update its
// eventsList.
if (self.defaultCalendar == thisEvent.calendar) {

[self.eventsList addObject:thisEvent];
}

[controller.eventStore saveEvent:controller.event span:EKSpanThisEvent error:&error];
**NSLog(@"thisEvent.id = %@", thisEvent.eventIdentifier);**
[self.tableView reloadData];
break;

case EKEventEditViewActionDeleted:
// When deleting an event, remove the event from the event store,
// and reload table view.
// If deleting an event from the currenly default calendar, then update its
// eventsList.
if (self.defaultCalendar == thisEvent.calendar) {
[self.eventsList removeObject:thisEvent];
}
**NSLog(@"thisEvent.id = %@", thisEvent.eventIdentifier);**
[controller.eventStore removeEvent:thisEvent span:EKSpanThisEvent error:&error];
[self.tableView reloadData];
break;

default:
break;
}
// Dismiss the modal view controller
[controller dismissModalViewControllerAnimated:YES];

}

关于iPhone - 如何导入所有日历事件,包括事件 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12311398/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com