无法将自定义日历添加到iOS

时间:2016-02-24 17:13:46

标签: ios objective-c ekevent

我遇到了无法将自定义日历保存到iOS的问题。它适用于模拟器,但如果我在真实设备上试用它,它似乎忽略了我正在做的一切。

我正在添加日历:

商店初始化为:store = [[EKEventStore alloc] init];

EKSource *localSource = nil;
        for (EKSource *source in store.sources) {
            if (source.sourceType == EKSourceTypeLocal){
                localSource = source;
                break;
            }
        }
        EKCalendar *cal;
        cal = [EKCalendar calendarForEntityType:EKEntityTypeEvent eventStore:store];
        cal.title = @"Custom Calendar Name";
        cal.source = localSource;

        NSLog(@"%@",cal); // Returns a calendar object, good

        NSError *error; // remains null

        if ([store saveCalendar:cal commit:YES error:&error]) {
            NSLog(@"success"); // is logged
        }

        //Added in response to answer. Did not help:
        [store commit:nil];

然而,如果我按照上面的代码运行:

    NSArray *allCalendars = [store calendarsForEntityType:EKEntityTypeEvent];
    for (EKCalendar *calendar in allCalendars) {
        NSLog(@"%@",calendar);
      // The calendar I just added does not show here, nor does it exist in the Calendar app - it does on the Simulator. All the other Calendars are printed out.

    }

我当然在此代码之前请求并授予对日历的访问权限。 我错过了什么?

编辑:我确实读过这个问题Can't create local calendar on iOS - 但解决方案是我已经在做的事情; EKEntityTypeEvent而不是Mask。

0 个答案:

没有答案