0

This is how I am adding an event to Ical I just dont know how to make the start date something other than the current day, as well as set the duration as an all day event.

> EKEventStore *store = [[EKEventStore alloc] init];
>         [store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
>             if (!granted) { return; }
>             EKEvent *event = [EKEvent eventWithEventStore:store];
>             event.title = @"Hits THermal DC I";
>             event.startDate = [NSDate date]; //today
>             event.endDate = [event.startDate dateByAddingTimeInterval:60*60];  //set 1 hour meeting
>             [event setCalendar:[store defaultCalendarForNewEvents]];
>             NSError *err = nil;
>             [store saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
>             NSString *savedEventId = event.eventIdentifier;  //this is so you can access this event later
>         }];
4

1 回答 1

1

要使用您自己的值创建任何日期,请执行以下操作:

NSCalendar* calendar=[NSCalendar currentCalendar];    

NSDateComponents* dateComps=[[NSDateComponents alloc] init];

[dateComps setYear:1990];
[dateComps setMonth:11];
[dateComps setDay:10];

NSDate* starDate=[calendar dateFromComponents:dateComps];

EKEventStore *store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
    if (!granted) { return; }
    EKEvent *event = [EKEvent eventWithEventStore:store];
    event.title = @"Hits THermal DC I";
    event.startDate = starDate
    event.endDate = [event.startDate dateByAddingTimeInterval:60*60];  //set 1 hour meeting
    [event setCalendar:[store defaultCalendarForNewEvents]];
    NSError *err = nil;
    [store saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
    NSString *savedEventId = event.eventIdentifier;  //this is so you can access this event later
}];
于 2013-10-30T23:06:35.120 回答