In my app, I am reading the calendar as soon as the app launches. So for the first time as per the guidelines my app asks for calendar access but what's happening is it never shows up and all i can see is the splash screen.
When i close the app i see the popup for granting access to calendar on my phone. I grant access to it and after that point everything works fine.
Here's my code :
-(NSArray*) listOfEventsInCalendar
{
_eventStore = [[EKEventStore alloc]init];
__block NSArray * events;
if ([_eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)])
{
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
/* iOS Settings > Privacy > Calendars > MY APP > ENABLE | DISABLE */
[_eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
if ( granted )
{
NSDate * startDate = [NSDate date];
NSDate * endDate = [NSDate distantFuture];
NSPredicate * predicate = [_eventStore predicateForEventsWithStartDate:startDate endDate:endDate calendars:nil];
events = [_eventStore eventsMatchingPredicate:predicate];
if (events) {
insideArray = [self castEvents:events];
}
else{
NSLog(@"No Events found in the calendar");
}
}
else
{
NSLog(@"User has not granted permission!");
}
dispatch_semaphore_signal(sema);
}];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
}
return insideArray;
}
What am i doing wrong??
Thanks,