2

我想使用 eventkit 将我的服务器中的事件添加到 ical 中。我可以以编程方式订阅 url,以便所有事件都可以在 ical 应用程序中自动同步。

4

1 回答 1

1
Synchronization is done from your side (Inside objective "c"). You need to fetching all events from server after hitting appropriate URL.
Parse it and save single event with the help of below method:  

-(void)addingEvents{

    EKEventStore *eventStore = [[EKEventStore alloc] init];

    EKEvent *event  = [EKEvent eventWithEventStore:eventStore];

    event.title     = <<Event Title>>;

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat: @"yyyy-MM-dd hh:mma"];
    [dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
    NSString *strDate = [dateFormatter stringFromDate:<<Your event date>>];

    NSDate *startDate = [dateFormatter dateFromString:strDate];

    [dateFormatter release];

    event.startDate = [[NSDate alloc] initWithTimeInterval:0 sinceDate:startDate];
    event.endDate   = [[NSDate alloc] initWithTimeInterval:600 sinceDate:event.startDate];
    NSArray *alertArray = [NSArray arrayWithObject:[EKAlarm alarmWithRelativeOffset:-300]];
    event.alarms = alertArray;

    [event setCalendar:[eventStore defaultCalendarForNewEvents]];
    NSError *err;
    [eventStore saveEvent:event span:EKSpanThisEvent error:&err];  
    if (err) {
        NSLog(@"Error occured : %@",[err localizedDescription]);
    }
    [eventStore release];

}
于 2013-03-08T11:46:53.373 回答