Reputation: 69
How to retrieve default calendar and reminder programmatically in ios, I have one simple project which have one button ,i want click on button to access the default reminder and calendar
I have done simple code for that but it is nort working properly following is the my sample code
#import "ViewController.h"
#import <EventKit/EventKit.h>
@interface ViewController ()
@end
@implementation ViewController
- (IBAction)btn:(id)sender {
EKEventStore *eventStore=[[EKEventStore alloc]init];
EKEvent *event =[EKEvent eventWithEventStore:eventStore];
NSDate *startDate=[[NSDate alloc]init];
NSDate *endDate =[[NSDate alloc]init];
event.title=@"Title for new event";
event.startDate=startDate;
event.endDate=endDate;
event.allDay=YES;
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
// if (err == noErr){
// UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"Event create" message:@"how about that?" delegate:nil cancelButtonTitle:@"okey" otherButtonTitles:nil];
//
// [alert show];
}
When I'm running it on iphone 4s reale device on that time it show's me the following error:
2013-03-13 09:52:22.638 remind[774:907] defaultCalendarForNewEvents failed: Error Domain=EKCADErrorDomain Code=1013 "The operation couldn’t be completed. (EKCADErrorDomain error 1013.)"
Upvotes: 1
Views: 512
Reputation: 69
this is my .h header file where u have to declare this below code:
uikit framework
#import <UIKit/UIKit.h>
#import <EventKitUI/EventKitUI.h>
#define ALERT_Reminder 0
@interface GaSchedulesDeWorming : UIViewController<UITableViewDataSource, UITableViewDelegate, EKEventEditViewDelegate>
{
EKEventStore *eventStore;
}
this ins my implementation file .m:
**#import <EventKitUI/EventKitUI.h>**
add these package
this below code is for open the by default calender for set the reminde in ipone
EKEventStore *eventStore=[[EKEventStore alloc]init];
EKEvent *event =[EKEvent eventWithEventStore:eventStore];
NSDate *startDate=[[NSDate alloc]init];
NSDate *endDate =[[NSDate alloc]init];
event.title=@"Title for new event";
event.startDate=startDate;
event.endDate=endDate;
event.allDay=YES;
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
eventStore=[[EKEventStore alloc]init];
__block BOOL accessGranted = NO;
if([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) {
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
accessGranted = granted;
dispatch_semaphore_signal(sema);
}];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
} else {
accessGranted = YES;
}
if (accessGranted) {
}
EKEventEditViewController *controller = [[EKEventEditViewController alloc]init];
}
Upvotes: 1