我正在使用以下代码将事件添加到我的日历中,但它没有显示任何错误,也没有保存到我的日历中。请帮忙。
EKEventStore *eventstore = [[EKEventStore alloc] init];
if([eventstore respondsToSelector:@selector(requestAccessToEntityType:completion:)])
{
[eventstore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
if(granted)
{
// if user granted your app to use calendar control will reach over hare
// add the code to add event to iCal that you are using previously for iOS5
EKEvent *event = [EKEvent eventWithEventStore: eventstore];
event.title = @"Title";
event.notes = @"Description";
event.location = @"Location";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
[dateFormat setTimeZone:timeZone];
[dateFormat setDateFormat:@"dd-MM-yyyy hh:mm a"];
NSDate *date = [dateFormat dateFromString:[NSString stringWithFormat:@"%@",[[eventsArray objectAtIndex:index] objectForKey:@"EventDate"]]];
event.startDate =date;
event.endDate = [date dateByAddingTimeInterval:36000];;
event.availability = EKEventAvailabilityFree;
[event setCalendar:[eventstore defaultCalendarForNewEvents]];
NSError *err;
[eventstore saveEvent:event span:EKSpanThisEvent error:&err];
}
else
{
NSLog(@"Calender not called");
// if user did not your app to use calendar control will reach over hare
}
}];
}