我已使用此代码将事件添加到 iphone 日历
-(void)setEvent:(NSString *)title withStartDate:(NSDate *)startDate withEndDate:(NSDate *)endDate completion:(void (^)(void))completionBlock
{
EKEventStore* store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (!granted)
{
return;
}
EKEvent *event = [EKEvent eventWithEventStore:store];
event.title = title;
event.startDate = startDate;
event.endDate = endDate;
[event setCalendar:[store defaultCalendarForNewEvents]];
NSError *err = nil;
[store saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
// NSString *savedEventId = event.eventIdentifier;
NSString* alertTitle;
NSString* msg;
if (err) {
alertTitle = @"Calendar was not set";
msg = @"Please set default calendar in settings.";
}
else
{
alertTitle = @"Event added";
msg = @"Event had been added in your calendar.";
}
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:alertTitle message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
completionBlock();
}];
}
但是添加事件非常慢。我必须等待大约 10-12 秒才能完成此方法。这是正常的还是我做错了什么?我已经搜索过相同的内容,但仍然没有运气。任何建议将不胜感激。