我正在从我的应用程序中的代码设置日历事件,并从我的日期选择器设置日期。这是我所拥有的:
-(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!");
}
}];
}
}
谁能告诉我我做错了什么?谢谢!