Follow by Email

Search This Blog

Monday, 30 June 2014

Add Event into iphone Calendar

//Add Event kit framework
EventKit.framework
//import 
#import <EventKit/EventKit.h>

//Copy below code and enjoy

-(IBAction)AddEvent:(id)sender
{
    NSString *dateString = @"Jul 09,2014 00:00";
    
    //Create a formater
    NSDateFormatter *formater =[[NSDateFormatter alloc] init];
    [formater setDateFormat:@"MMM dd,yyyy HH:mm"];
    NSDate *startDate =[formater dateFromString:dateString];
    
    NSLog(@"current date %@",[NSDate date]);
    EKEventStore *store = [[EKEventStore alloc] init];
    [store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
        if (!granted) { return; }
        EKEvent *event = [EKEvent eventWithEventStore:store];
        event.title = @"My Birthday";
        event.startDate = startDate;//[NSDate date]; //today
        event.endDate = [event.startDate dateByAddingTimeInterval:60*60];  //set 1 hour meeting
        [event setCalendar:[store defaultCalendarForNewEvents]];
        NSError *err = nil;
        [store saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
        NSString *savedEventId = event.eventIdentifier;  //this is so you can access this event later
    }];
    

}

No comments:

Post a Comment