gpt4 book ai didi

ios - 如何在 ios 6 上创建和保存 EKCalendar

转载 作者:行者123 更新时间:2023-11-30 12:44:44 24 4
gpt4 key购买 nike

我在创建 EKCalendar 时遇到问题,一切看起来都不错,但当我去列出我的日历时,它没有显示。我还去查看我的日历应用程序中的日历列表,但它不存在。有什么想法吗?

这是我用于创建日历的按钮代码:

- (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);
}

这是我列出日历的按钮代码,但我的新日历从未包含在内!

- (IBAction)two:(id)sender {

NSArray *calendars = [eventStore calendarsForEntityType:EKEntityTypeEvent];

for (EKCalendar* cal in calendars){
NSLog(@"%@",cal.title);
}

}

提前谢谢您!

最佳答案

我找到了解决方案。问题是,当 iCloud 日历打开时,它会隐藏日历应用程序中本地创建的日历。要绕过此问题,解决方案是将新日历添加到 iCloud 源:

    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 - 如何在 ios 6 上创建和保存 EKCalendar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41775899/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com