如何在 ios 6 上创建和保存 EKCalendar [英] How to create and save EKCalendar on ios 6
问题描述
我在创建 EKCalendar 时遇到问题,一切看起来都很好,但是当我去列出我的日历时,它没有显示出来.我还去我的日历应用程序中检查我的日历列表,但它不存在.有什么想法吗?
I'm having an issue where I create my EKCalendar and everything looks good but then when I go to list my calendars, it doesn't show up. I also go to check my calendar list in my calendar app but it is non existant. Any thoughts?
这是我创建日历的按钮代码:
Here is my button code to create my calendar:
- (IBAction)one:(id)sender {
NSString* calendarName = @"My Cal";
EKCalendar* calendar;
// Get the calendar source
EKSource* localSource;
for (EKSource* source in eventStore.sources) {
if (source.sourceType == EKSourceTypeLocal)
{
localSource = source;
break;
}
}
if (!localSource)
return;
calendar = [EKCalendar calendarWithEventStore:eventStore];
calendar.source = localSource;
calendar.title = calendarName;
NSError* error;
bool success= [eventStore saveCalendar:calendar commit:YES error:&error];
if (error != nil)
{
NSLog(error.description);
// TODO: error handling here
}
NSLog(@"cal id = %@", calendar.calendarIdentifier);
}
这是我列出日历的按钮代码,但我的新日历从未包含在内!
And here is my button code to list the calendar, but my new calendar is never included!
- (IBAction)two:(id)sender {
NSArray *calendars = [eventStore calendarsForEntityType:EKEntityTypeEvent];
for (EKCalendar* cal in calendars){
NSLog(@"%@",cal.title);
}
}
提前谢谢你!
推荐答案
我找到了解决方案.问题是当 iCloud 日历打开时,它会从日历应用程序中隐藏本地创建的日历.要绕过这个问题,解决方案是向 iCloud 源添加一个新日历:
I found a solution. The problem is that when iCloud calendars switched on, it hides the locally created ones from the calendar app. To bypass this problem the solution is to add a new calendar to iCloud source:
for (EKSource *source in self.eventStore.sources)
{
if (source.sourceType == EKSourceTypeCalDAV &&
[source.title isEqualToString:@"iCloud"]) //Couldn't find better way, if there is, then tell me too. :)
{
localSource = source;
break;
}
}
if (localSource == nil)
{
for (EKSource *source in self.eventStore.sources)
{
if (source.sourceType == EKSourceTypeLocal)
{
localSource = source;
break;
}
}
}
这篇关于如何在 ios 6 上创建和保存 EKCalendar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!