我使用以下代码将事件添加到系统日历。系统版本为iOS 7.1
EKEventStore *store = [[EKEventStore alloc] init];
if ([store respondsToSelector:@selector(requestAccessToEntityType:completion:)])
{
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (!granted) { return; }
EKEvent *event = [EKEvent eventWithEventStore:store];
[event setTitle:[localStore eventTitle]];
[event setStartDate:[localStore eventStartDate]];
[event setEndDate:[localStore eventEndDate]];
[event setCalendar:[store defaultCalendarForNewEvents]]; // Error in this line
[store saveEvent:event span:EKSpanThisEvent commit:YES error:nil];
NSString *savedEventId = [event eventIdentifier]; // return nil
}];
}
错误显示在控制台
中defaultCalendarForNewEvents failed: Error Domain=EKCADErrorDomain Code=1013 "The operation couldn’t be completed. (EKCADErrorDomain error 1013.)"
我已经花了几个小时来解决这个问题,但我不能。所以请帮助我。提前谢谢。
答案 0 :(得分:0)
EKEventStore *eventStore = [[[EKEventStore alloc] init] autorelease];
if ([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)])
{
// iOS 6 and later
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted) {
// code here for when the user allows your app to access the calendar
[self performCalendarActivity:eventStore];
} else {
// code here for when the user does NOT allow your app to access the calendar
}
}];
}