iPhone Event Kit:以编程方式创建EKCalendar? [英] iPhone Event Kit : programmatically create a EKCalendar?
本文介绍了iPhone Event Kit:以编程方式创建EKCalendar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的应用中插入事件,因此可以在iPhone Calendar.app中查看它们。但由于我不想将用户事件与我的应用程序中的用户事件混合,我想创建一个类似MyApp Events的EKCalendar
I would like to insert events in my app, so they can be viewed in iPhone Calendar.app. But since I don't want to mix the user events with those from my app, I wanted to create a EKCalendar like "MyApp Events"
这可能吗?你会如何过滤你的活动?
Is this possible ? How would you filter your events otherwise ?
谢谢!
推荐答案
绝对可以创建自己的日历 - 需要iOS 5才能获得:
It is absolutely possible to create your own calendar - the catch is that you need iOS 5:
EKEventStore* eventStore = [[EKEventStore alloc] init];
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
}
这篇关于iPhone Event Kit:以编程方式创建EKCalendar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文