关于iOS 插入日历功能以报错Error Domain=EKErrorDomain Code=1 “尚未设定日历。” UserInfo={NSLocalizedDescription=尚未设定日历。}

发布时间:2024-11-21 06:43

Apple 日历 (iOS/macOS): 自带日程管理功能,与Apple设备无缝配合。 #生活常识# #时间管理建议# #日程管理APP#

处理报错

Error Domain=EKErrorDomain Code=1 "尚未设定日历。" UserInfo={NSLocalizedDescription=尚未设定日历。}

出现这个错误的原因是由于你在为事件设置日历时,设置了nil,如下:

[event setCalendar:[self.eventStore defaultCalendarForNewEvents]];

也就是 [self.eventStore defaultCalendarForNewEvents] 为nil。

出现这个问题的原因并不是代码出现了问题,暂时我也没有办法从代码上解决这个问题,因为现在用户自己都无法在日历中插入事件,解决办法如下图


自定义日历

如果你想添加属于自己App的日历的话,可以这样

- (EKCalendar *)getCalendar{

    EKCalendar *calendar = nil;

    BOOL needAdd = YES;

    for (EKCalendar *ekcalendarin [_eventStorecalendarsForEntityType:EKEntityTypeEvent]) {

        if ([ekcalendar.titleisEqualToString:@"My calendar"]) {

            needAdd = NO;

            calendar = ekcalendar;

            break;

        }

    }

    if (needAdd) {

        EKSource *localSource = nil;

        for (EKSource *sourcein_eventStore.sources)

        {

            //iCloud 是否存在

            if (source.sourceType ==EKSourceTypeCalDAV && [source.titleisEqualToString:@"iCloud"])

            {

                localSource = source;

                break;

            }

        }

        if (localSource == nil)

        {

            //本地 是否存在

            for (EKSource *sourcein_eventStore.sources) {

                if (source.sourceType ==EKSourceTypeLocal)

                {

                    localSource = source;

                    break;

                }

            }

        }

        if (localSource) {

            calendar = [EKCalendarcalendarForEntityType:EKEntityTypeEventeventStore:_eventStore];

            calendar.source = localSource;

            calendar.title = APPSetting.kApp_Name;//自定义日历标题

            calendar.CGColor = [UIColoryellowColor].CGColor;//自定义日历颜色

            NSError* error;

            [_eventStore saveCalendar:calendar commit:YESerror:&error];

        }

    }

    return calendar;

}

将这个方法生成的日历设置为事件的日历

[event setCalendar:[self  getCalendar]];

效果如下


iOS 日历插入事件基本功能

请参照

http://www.jianshu.com/p/2642b0e3cac5

这边就不予以赘述了

网址:关于iOS 插入日历功能以报错Error Domain=EKErrorDomain Code=1 “尚未设定日历。” UserInfo={NSLocalizedDescription=尚未设定日历。} https://www.yuejiaxmz.com/news/view/169713

相关内容

【日历app合集】好用的日历app推荐
日历软件有哪些?日历软件推荐
desktopcal桌面日历
日历app哪个好
探秘Obsidian全功能日历插件:连接任务、笔记与生活节奏
日程日历app
生活日历去广告版
日历
简约日历最新版下载
日程日历2024官方下载

随便看看