0

我正在从我的应用程序中的代码设置日历事件,并从我的日期选择器设置日期。这是我所拥有的:

-(void)setCalenderEvent
{
    EKEventStore *eventStore = [[EKEventStore alloc] init];
    EKEvent *event = [EKEvent eventWithEventStore:eventStore];
    NSDate *startDate = [[NSDate alloc] init];
    NSDate *endDate = [[NSDate alloc] init];
    event.title = @"Test from date picker";
    // event.startDate = startDate;
    // event.endDate = endDate;
    NSDate *selectedDate = self.datePickerForReminder.date;
    event.startDate = selectedDate;
    event.allDay = NO;
    event.notes = @"Created by Quick Reminders!!";
    /* iOS 6 requires the user grant your application access to the Event Stores */
    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!");
                 [event setCalendar:[eventStore defaultCalendarForNewEvents]];
                 NSError *err;
                 [eventStore saveEvent:event span:EKSpanThisEvent error:&err];
                 if (err == noErr){
                     NSLog(@"No Error");
                 }
                 [startDate release];
                 [endDate release];
                 [eventStore release];

             }
             else
             {
                 NSLog(@"User has not granted permission!");
             }
         }];
    }
}

谁能告诉我我做错了什么?谢谢!

4

1 回答 1

0

我能够得到它!您需要一个跨度时间(添加结束时间)。

event.endDate = [selectedDate dateByAddingTimeInterval:30*60];
于 2013-07-13T05:10:56.467 回答