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

无法将自定义日历添加到iOS,ios,objective-c,ekevent,Ios,Objective C,Ekevent,我面临无法将自定义日历保存到iOS的问题。它在模拟器上工作,但如果我在真实设备上尝试,它似乎忽略了我正在做的一切 我正在添加日历,如下所示: 存储初始化为:store=[[EKEventStore alloc]init] EKSource *localSource = nil; for (EKSource *source in store.sources) { if (source.sourceType == EKSourceTypeLocal){

我面临无法将自定义日历保存到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.

    }
当然,在此代码之前,我请求并授权访问日历。 我错过了什么


编辑:我确实读过这个问题——但解决方案是我已经在做的事情;eEntityTypeEvent而不是Mask。

您使用的日历是什么?我尝试将日历添加到本地商店哦,抱歉。我以为您正在尝试创建自定义日历视图。我的错