After some 2 days research i found the solution-i put the event saving code in dispatch_async
here is my updated method for adding event-
-(void)setEvent:(NSString *)title withStartDate:(NSDate *)startDate withEndDate:(NSDate *)endDate withResecheduling:(BOOL)rescheduling completion:(void (^)(void))completionBlock
{
[[BusyIndicator sharedInstance] startIndicator];
EKEventStore* store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (!granted)
{
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
EKEvent *event = [EKEvent eventWithEventStore:store];
event.title = title;
event.startDate = startDate;
event.endDate = endDate;
[event setCalendar:[store defaultCalendarForNewEvents]];
NSError *err = nil;
[store saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
// NSString *savedEventId = event.eventIdentifier;
if (!rescheduling) {
NSString* alertTitle;
NSString* msg;
if (err) {
alertTitle = @"Calendar was not set";
msg = @"Please set default calendar in settings.";
}
else
{
alertTitle = @"Event added";
msg = @"Event has been added in your calendar.";
}
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:alertTitle message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
[[BusyIndicator sharedInstance] stopIndicator];
completionBlock();
});
}];
}