:: iDavidStudio ::..

Dev log

Archive for September, 2012

iOS6 EKEventStore requires users grant access before getting any calender / reminder data.

without comments

ios App wont be able get any data from the Calendar on the iOS6 system if you don’t call the requestAccessToEntityType function to prompt a dialog to ask your users to grant access to your app to access the Calendar/Reminder. Below is the sample code:


EKEventStore    *eventStore = [[EKEventStore alloc] init];

//— This method “checkIsDeviceVersionHigherThanRequiredVersion” can be remove and use the official method to detect if user is using ios6 or later.

//—if([self checkIsDeviceVersionHigherThanRequiredVersion:@”6.0″]) {

if([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) {
// iOS 6 and later
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {

// perform the main thread here to avoid any delay. normally seems to be 10 to 15 sec delay.
[self performSelectorOnMainThread: @selector(presentEventEditViewControllerWithEventStore:) withObject:eventStore waitUntilDone:NO];


if (granted){
//—- codes here when user allow your app to access theirs’ calendar.

//—– codes here when user NOT allow your app to access the calendar.






– (void)presentEventEditViewControllerWithEventStore:(EKEventStore*)eventStore
EKEventEditViewController* eventEditVC = [[EKEventEditViewController alloc] init];
eventEditVC.eventStore = eventStore;

EKEvent* event = [EKEvent eventWithEventStore:eventStore];
event.title = @”My Event”;
event.startDate = [NSDate date];
event.endDate = [NSDate date];
event.URL = [NSURL URLWithString:@”http://www.idavid.com.au”];
event.notes = @”This is just a test event.”;
event.allDay = YES;
eventEditVC.event = event;

eventEditVC.editViewDelegate = self;

[self presentViewController:eventEditVC animated:YES completion:nil];




//   Below is a block for checking is current ios version higher than required version.


– (BOOL)checkIsDeviceVersionHigherThanRequiredVersion:(NSString *)requiredVersion
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];

if ([currSysVer compare:requiredVersion options:NSNumericSearch] != NSOrderedAscending)
return YES;

return NO;

Written by admin

September 21st, 2012 at 1:40 am

Posted in iPhone Dev