objective-c – 目标C-iCal未在iOS 9中为其创建自定义日历和新事件

objective-c – 目标C-iCal未在iOS 9中为其创建自定义日历和新事件,第1张

概述这在iOS 8中完美运行. 但是在iOS 9中创建问题.这里是代码: self.eventManager.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { if (granted) { // Create a 这在iOS 8中完美运行.

但是在iOS 9中创建问题.这里是代码:

self.eventManager.eventStore requestAccesstoEntityType:EKEntityTypeEvent completion:^(BOol granted,NSError *error) {        if (granted) {            // Create a new calendar.            EKCalendar *calendar = [EKCalendar calendarForEntityType:EKEntityTypeEvent                                                          eventStore:self.eventManager.eventStore];            // Set the calendar Title.            calendar.Title = @"<APP name>";            calendar.CGcolor=APP_Blue_color.CGcolor;            // Find the proper source type value.            for (int i=0; i<self.eventManager.eventStore.sources.count; i++) {                EKSource *source = (EKSource *)[self.eventManager.eventStore.sources objectAtIndex:i];                EKSourceType currentSourceType = source.sourceType;                if (currentSourceType == EKSourceTypeLocal) {                    calendar.source = source;                    break;                }            }            // Save and commit the calendar.            NSError *error;            [self.eventManager.eventStore saveCalendar:calendar commit:YES error:&error];            // If no error occurs then turn the editing mode off,store the new calendar IDentifIEr and reload the calendars.            if (error == nil) {                // Turn off the edit mode.                // Store the calendar IDentifIEr.                [self.eventManager saveCustomCalendarIDentifIEr:calendar.calendarIDentifIEr];self.eventManager.selectedCalendarIDentifIEr=calendar.calendarIDentifIEr;//chirag            }            else{                // display the error description to the deBUGger.                NSLog(@"CREATE_CALENDER %@",[error localizedDescription]);            }        }        else        {            UIAlertVIEw *alert=[[UIAlertVIEw alloc] initWithTitle:@"" message:@"Please give permission to access your iPhone calender." delegate:nil cancelbuttonTitle:@"Ok" otherbuttonTitles: nil];            [alert show];        }    }];

它给了我成功的消息,但没有在iPhone日历中创建我的应用程序日历.

我虽然因为没有设置事件而没有显示它.所以我也尝试设置新事件.

但它给了我以下代码&创建新事件时出错.

// Create a new event object.    EKEvent *event = [EKEvent eventWithEventStore:self.eventManager.eventStore];    // Set the event Title.    event.Title = Title;    // Set its calendar.    event.calendar = [self.eventManager.eventStore calendarWithIDentifIEr:self.eventManager.selectedCalendarIDentifIEr];    // Set the start and end dates to the event.    event.startDate = startDate;    event.endDate = endDate; // Save and commit the event.    NSError *error;    if ([self.eventManager.eventStore saveEvent:event span:EKSpanThisEvent commit:YES error:&error]) {        // Call the delegate method to notify the caller class (the VIEwController class) that the event was saved.        return true;    }    else{        // An error occurred,so log the error description.        NSLog(@"%@",[error localizedDescription]);    return false;    }

它在内部给出以下错误,但它会在NSError对象中返回:

Error getting shared calendar invitations for entity types 3 from daemon: Error Domain=EKCADErrorDomain Code=1014 "(null)"
解决方法 问题是,当iCloud日历打开时,它会从日历应用程序中隐藏本地创建的日历.要绕过此问题,解决方案是向iCloud源添加新日历:

for (EKSource *source in self.eventStore.sources){    if (source.sourceType == EKSourceTypeCalDAV &&        [source.Title isEqualToString:@"iCloud"]) //This is a patch.    {        localSource = source;        break;    }}if (localSource == nil){    for (EKSource *source in self.eventStore.sources)    {        if (source.sourceType == EKSourceTypeLocal)        {            localSource = source;            break;        }    }}
总结

以上是内存溢出为你收集整理的objective-c – 目标C-iCal未在iOS 9中为其创建自定义日历和新事件全部内容,希望文章能够帮你解决objective-c – 目标C-iCal未在iOS 9中为其创建自定义日历和新事件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1227896.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存