Ios6 iOS 6中未正确添加自当前日期起55年的EventKit事件

Ios6 iOS 6中未正确添加自当前日期起55年的EventKit事件,ios6,calendar,ekeventkit,Ios6,Calendar,Ekeventkit,我想添加从当前日期算起55年的事件。使用iOS 6的以下代码,事件被添加到日历中,事件名称为New event,事件被设置为all day。根据我的代码,这是不正确的。对于从当前日期算起55年以下的事件,代码工作正常 -(void)addEvent{ EKEventStore *es = [[EKEventStore alloc] init]; EKAuthorizationStatus authorizationStatus = [EKEventStore authorizat

我想添加从当前日期算起55年的事件。使用iOS 6的以下代码,事件被添加到日历中,事件名称为New event,事件被设置为all day。根据我的代码,这是不正确的。对于从当前日期算起55年以下的事件,代码工作正常

-(void)addEvent{
    EKEventStore *es = [[EKEventStore alloc] init];
    EKAuthorizationStatus authorizationStatus = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];
    BOOL needsToRequestAccessToEventStore = (authorizationStatus == EKAuthorizationStatusNotDetermined);

    if (needsToRequestAccessToEventStore) {
        [es requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
            if (granted) {
                 [self loadAllEventsForStore:es];
            } else {
                NSLog(@"Not Granted");
            }
        }];
    } else {
        BOOL granted = (authorizationStatus == EKAuthorizationStatusAuthorized);
        if (granted) {
            [self loadAllEventsForStore:es];
        } else {
             NSLog(@"Not Granted");
        }
    }
}

-(void)loadAllEventsForStore:(EKEventStore*)store{
  [self setEventForStore:store yearfromCurrentDate:55];
  [self setEventForStore:store yearfromCurrentDate:56];

}

-(void)setEventForStore:(EKEventStore*)store yearfromCurrentDate:(int)year{
    EKEvent *event = [EKEvent eventWithEventStore:store];
    event.title = [NSString stringWithFormat:@"Event %d",eventid++];
    NSLog(@"=========== %@ ==============", event.title);

    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *comps = [NSDateComponents new];
    [comps setDay:05];
    [comps setMonth:1];
    [comps setYear:year];

    NSDate *startDate = [calendar dateByAddingComponents:comps toDate:[NSDate date] options:0];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

    [dateFormatter setDateFormat:@"dd-MM-yyyy"];
    NSString *startDateString = [dateFormatter stringFromDate:startDate];
    NSLog(@"Start Date = %@", startDateString);

    event.startDate = startDate;
    NSDate *endDate = [event.startDate dateByAddingTimeInterval:60*60];;

    [dateFormatter setDateFormat:@"dd-MM-yyyy"];
    NSString *endDateString = [dateFormatter stringFromDate:endDate];
    NSLog(@"End Date date = %@", endDateString);

    event.endDate = endDate;

    [event setCalendar:[store defaultCalendarForNewEvents]];
    NSError *err = nil;
    BOOL save=[store saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
    if (save && err==nil) {
        NSLog(@"Event %@ is added sucessfully",event.title);
    }else
        NSLog(@"Event %@ is not added",event.title);

     NSLog(@"==================================");
}
以编程方式添加事件后日历应用程序的屏幕截图:

    Console Output:
2014-01-22 15:13:08.789 TestApp[19094:907] =========== Event 0 ==============
2014-01-22 15:13:08.796 TestApp[19094:907] Start Date = 27-02-2069
2014-01-22 15:13:08.798 TestApp[19094:907] End Date date = 27-02-2069
2014-01-22 15:13:08.884 TestApp[19094:907] Event Event 0 is added sucessfully
2014-01-22 15:13:08.886 TestApp[19094:907] ==================================
2014-01-22 15:13:08.889 TestApp[19094:907] =========== Event 1 ==============
2014-01-22 15:13:08.893 TestApp[19094:907] Start Date = 27-02-2070
2014-01-22 15:13:08.896 TestApp[19094:907] End Date date = 27-02-2070
2014-01-22 15:13:08.923 TestApp[19094:907] Event Event 1 is added sucessfully
2014-01-22 15:13:08.924 TestApp[19094:907] ==================================