将事件从iCal检索到我的iOS应用程序中

时间:2012-11-27 09:43:10

标签: objective-c icalendar eventkit

你好堆叠的人!

我正在寻找将iCal中的事件导入iOS应用程序(?)

的任何教程

找不到任何东西我只发现反过来我的意思是将iOS应用程序中的事件添加到iCal中...... :(

我找到了这个很好的教程:http://neilang.com/entries/using-eventkit-in-ios/ 我知道我必须使用EventKit.framework但它并没有帮助我开始......

你对这个教程有什么想法吗?很高兴使用它;)

有一个美好的一天/早上/傍晚/下午。 ;)

此致

1 个答案:

答案 0 :(得分:2)

我很抱歉但是!我找到了答案;)

这是代码:

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)