Key word: EKEventStore, EventKit Framework, iCal, user permissions, requestAccessToEntityType, Privacy settings, ios6
Get contacts of all your emergency needs on single tap. Download Quick-Finder for iPhone
How To Add Events To Calendar in iOS 6
Get contacts of all your emergency needs on single tap. Download Quick-Finder for iPhone
For iOS 6, You need to take permission from user. For this you have to execute the following code.
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 = [NSString stringWithStdString:eventName] ;
event.startDate = [NSDate date];
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
}
else
{
// if user did not your app to use calendar control will reach over hare
}
}];
}
If user did not allow your app to use calendar you can also suggest him to allow and shows alert massage like this
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Info" message:@"Pls go to Setting----> Privacy -----> Calendar ----> Choose App Name. " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
Really nice and honest advice! I love it, Absolutely Brilliant Post! http://www.imobdevtech.com
ReplyDeleteiPhone App Development :: && :: Mobile and Web Application Development