gpt4 book ai didi

objective-c - 获取实体类型 3 的共享日历邀请时出错,Xcode 6.1.1。 EKCalender、EKSource、EKEventstore 和 Objective C

转载 作者:太空狗 更新时间:2023-10-30 03:20:24 25 4
gpt4 key购买 nike

我正在开发日历应用程序。我正在尝试使用分配的 EKCalender 保存 EKEvent。但是当我尝试运行以下代码时,它给了我错误。请帮忙

-(BOOL)createEventWithTitle:(NSString *)paramTitle startDate:(NSDate *)paramStartDate endDate:(NSDate *)paramEndDate inCalendar:(EKCalendar *)paramCalendar inEventStore:(EKEventStore *)paramStore notes:(NSString *)paramNotes 
{
BOOL result = NO;

//paramCalendar = [self.eventStoreiReportShifts defaultCalendarForNewEvents];
if (self.eventsAccessGranted) {
NSArray *caledars = [self.eventStore calendarsForEntityType:EKEntityTypeEvent];
self.selectedCalendarEventKitIdentifier = [[NSUserDefaults standardUserDefaults] objectForKey:@"eventkit_cal_identifiers_string"];
for(EKCalendar *aCal in caledars){
if([aCal.calendarIdentifier isEqualToString:self.selectedCalendarEventKitIdentifier]){
paramCalendar = [self.eventStore calendarWithIdentifier:[[NSUserDefaults standardUserDefaults] objectForKey:@"eventkit_cal_identifiers_string"]];
}
}
for (EKSource *source in self.eventStore.sources) {
if (source.sourceType == EKSourceTypeCalDAV) {
paramCalendar.source = source;
break;
} else if(source.sourceType == EKSourceTypeLocal){
paramCalendar.source = source;
break;
}
}

}else{
return NO;
}

/* If a calendar does not allow modification of its contents
then we can not insert an event into it */
if (paramCalendar.allowsContentModifications == NO) {
NSLog (@ "\n\n The selected calendar does not allow modifications.");
return NO;
}
/* Create an event */

EKEvent * event = [EKEvent eventWithEventStore:paramStore];

event.calendar = paramCalendar;
/* Set the properties of the event such as its title,
start date / time, end date / time, etc. */
event.title = paramTitle;
event.notes = paramNotes;
event.startDate = paramStartDate;
event.endDate = paramEndDate;
/* Finally, save the event into the calendar */
NSError * saveError = nil;
result = [paramStore saveEvent:event
span:EKSpanThisEvent
error:&saveError];
if (result == NO) {
NSLog (@ "\n\n An error occurred = %@", saveError);
}
return result;
}

上面的代码给出了如下错误

    CalendarCalculations[1668:45103] 
Error getting shared calendar invitations for entity types 3 from
daemon: Error Domain=EKCADErrorDomain Code=1013
"The operation couldn’t be completed. (EKCADErrorDomain error 1013.)"

请问我怎样才能摆脱它?

最佳答案

我在我的应用程序中遇到了同样的问题。我注意到调用 calendarWithIdentifier 方法时会发生错误。

EKCalendar *selectedCalendar = [self.eventStore calendarWithIdentifier:selectedCalendarIdentifier];

我不知道为什么会发生这种情况,但我想当您的设备中没有任何共享日历时就会发生这种情况。这是一个链接 About shared iCloud calendars

我找到了解决方案 here我用下一个代码片段在我的应用程序中修复了它:

EKCalendar *selectedCalendar = [EKCalendar calendarForEntityType:EKEntityTypeEvent eventStore:self.eventStore];
NSString *selectedCalendarIdentifier = [[NSUserDefaults standardUserDefaults] objectForKey:@"selectedCalendarIdentifier"];

//instead of getting calendar by identifier
//get all calendars and check matching in the cycle
NSArray *allCalendars = [self.eventStore calendarsForEntityType:EKEntityTypeEvent];
for (EKCalendar *calendar in allCalendars) {
if ([calendar.calendarIdentifier isEqualToString:selectedCalendarIdentifier]) {
selectedCalendar = calendar;
break;
}
}

当然这不是很好的方法,但错误消失了。希望对你有帮助 ;)

关于objective-c - 获取实体类型 3 的共享日历邀请时出错,Xcode 6.1.1。 EKCalender、EKSource、EKEventstore 和 Objective C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28258204/

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