3
如何在iOS 5中将日历(而不是事件)添加到EKEventStore?使用EventKit向EKEventStore添加新日历
如何在iOS 5中将日历(而不是事件)添加到EKEventStore?使用EventKit向EKEventStore添加新日历
我捕捉到一个例外,除非我也没有:
// 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;
当然,看看其他EKSourceType枚举,看看哪一个适合您的需求。
EKEventStore *calendarStore = [[EKEventStore alloc] init];
EKCalendar *calendar = [EKCalendar calendarWithEventStore:calendarStore];
NSString *calendarID = [calendar calendarIdentifier]; /// cache this in your app data for retrieval later
[calendar setTitle:@"New Calendar"];
NSError *error = nil;
BOOL saved = [calendarStore saveCalendar:calendar commit:YES error:&error];
if (!saved) {
// handle error....
}
无源保存会导致错误 –
所有这些只会添加一个无法从默认日历应用程序中看到的日历。有没有人遇到类似的问题? 有什么我可能错过了..或必须补充? – codeburn