【问题标题】:Retrieving Events from iCal into my iOS application从 iCal 检索事件到我的 iOS 应用程序
【发布时间】:2012-11-14 21:38:39
【问题描述】:
大家好!
我正在寻找任何将事件从 iCal 导入 iOS 应用程序的教程 (?)
找不到任何东西我只能找到相反的方式我的意思是从 iOS 应用程序添加事件到 iCal... :(
我发现了这个不错的教程:http://neilang.com/entries/using-eventkit-in-ios/
我知道我必须使用 EventKit.framework 但这并不能帮助我很好地开始......
您对此有任何教程的想法吗?会很高兴使用它;)
祝你有美好的一天/早上/晚上/下午。 ;)
问候
【问题讨论】:
标签:
objective-c
icalendar
eventkit
【解决方案1】:
我很抱歉,但是!我找到了答案;)
这里是代码:
EKEventStore *eventStore = [[EKEventStore alloc] init];
NSDate *startDate = [NSDate date];
NSDate *endDate = [NSDate distantFuture];
//NSArray *calendarArray = [NSArray arrayWithObject:defaultCalendar];
NSPredicate *predicate = [eventStore predicateForEventsWithStartDate:startDate
endDate:endDate
calendars:nil];
NSArray *events = [eventStore eventsMatchingPredicate:predicate];
if ([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)])
{
/* iOS Settings > Privacy > Calendars > MY APP > ENABLE | DISABLE */
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
if ( granted )
{
NSLog(@"User has granted permission!");
NSLog(@"events %@", events);
}
else
{
NSLog(@"User has not granted permission!");
}
}];
}
这是要求用户允许应用程序获取日历(默认情况下所有日历)
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)