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

处理报错

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

这边就不予以赘述了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
ipa equestOrder IOS 14.8 版本手机报错,信息如下,其他版本不报错。 equestOrder failed: {"code":0,"message":"Payment_appleiap:Error Domain=SKErrorDomain Code=0 \"An unknown error occurred\" UserInfo={NSLocalizedDescription=An unknown error occurred, NSUnderlyingError=0x282b4a670 {Error Domain=ASDErrorDomain Code=500 \"Unhandled exception\" UserInfo={NSUnderlyingError=0x282b4bcf0 {Error Domain=AMSErrorDomain Code=203 \"Bag Load Failed\" UserInfo={NSLocalizedFailureReason=Unable to retrieve p2-product-offers-batch-limit because we failed to load the bag., NSLocalizedDescription=Bag Load Failed, NSUnderlyingError=0x282b4b510 {Error Domain=AMSErrorDomain Code=203 \"Bag Load Failed\" UserInfo=0x283049b40 (not displayed)}}}, NSLocalizedFailureReason=An unknown error occurred, NSLocalizedDescription=Unhandled exception}}},https://ask.dcloud.net.cn/article/282","errCode":0,"errMsg":"Payment_appleiap:Error Domain=SKErrorDomain Code=0 \"An unknown error occurred\" UserInfo={NSLocalizedDescription=An unknown error occurred, NSUnderlyingError=0x282b4a670 {Error Domain=ASDErrorDomain Code=500 \"Unhandled exception\" UserInfo={NSUnderlyingError=0x282b4bcf0 {Error Domain=AMSErrorDomain Code=203 \"Bag Load Failed\" UserInfo={NSLocalizedFailureReason=Unable to retrieve p2-product-offers-batch-limit because we failed to load the bag., NSLocalizedDescription=Bag Load Failed, NSUnderlyingError=0x282b4b510 {Error Domain=AMSErrorDomain Code=203 \"Bag Load Failed\" UserInfo=0x283049b40 (not displayed)}}}, NSLocalizedFailureReason=An unknown error occurred, NSLocalizedDescription=Unhandled exception}}}
最新发布
06-03
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值