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

标签 objective-c iphone xcode ekeventstore ekeventkit

我正在开发日历应用程序。我正在尝试使用分配的 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/

相关文章:

iphone - 访问子ViewController中的TabBarController变量

android - OpenGL ES 2.0 的纵向和横向模式

ios - 错误 ITMS-90034 : Missing or invalid signature

swift - 如何只填充自定义 UIView 矩形的一部分?

iphone - 如何在iphone中隐藏按钮的选择

ios - 没有缓存的 Afnetworking 离线模式(像 Android 中的 Imageloader 一样保存到文件中)

objective-c - 内存泄漏和僵尸有什么区别?

iphone - ARC 在 iOS 4.3 中不工作

Xcode 卡在索引上

objective-c - 查找文件大小