/ Published in: Objective C
This code will work only for iOS4.0
Expand |
Embed | Plain Text
#import "EventTestViewController.h" #import <EventKit/EventKit.h> @implementation EventTestViewController - (void)viewDidLoad { [super viewDidLoad]; EKEventStore *eventStore = [[EKEventStore alloc] init]; EKEvent *event = [EKEvent eventWithEventStore:eventStore]; event.title = @"EVENT TITLE"; [event setCalendar:[eventStore defaultCalendarForNewEvents]]; NSError *err; [eventStore saveEvent:event span:EKSpanThisEvent error:&err]; } -(IBAction)btnSyncCalendar:(id)sender{ Class aMsgClass = NSClassFromString(@"EKEventStore"); if(!aMsgClass) return; [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; // dayName dayOfMonth monthName timing dateForSync EKEventStore *eventStore = [[EKEventStore alloc] init]; EKEvent *event = [EKEvent eventWithEventStore:eventStore]; event.title = strTitle; if([strStart hasSuffix:@"pm"]){ strStart=[NSString stringWithFormat:@"%02i:00:00",([[[strStart componentsSeparatedByString:@"pm"] objectAtIndex:0] intValue]+12)]; } else { strStart=[NSString stringWithFormat:@"%02i:00:00",([[[strStart componentsSeparatedByString:@"pm"] objectAtIndex:0] intValue])]; } if([strEnd hasSuffix:@"pm"]){ strEnd=[NSString stringWithFormat:@"%02i:00:00",([[[strEnd componentsSeparatedByString:@"pm"] objectAtIndex:0] intValue]+12)]; } else { strEnd=[NSString stringWithFormat:@"%02i:00:00",([[[strEnd componentsSeparatedByString:@"pm"] objectAtIndex:0] intValue])]; } event.startDate = [dateFormat dateFromString:strStart]; event.endDate = [dateFormat dateFromString:strEnd]; NSLog(@"\n\nTitle is %@\nStartDate is %@\nEnd date is %@.",event.title,event.startDate,event.endDate); [event setCalendar:[eventStore defaultCalendarForNewEvents]]; NSError *err; [eventStore saveEvent:event span:EKSpanThisEvent error:&err]; } [dateFormat release]; dateFormat=nil; }
You need to login to post a comment.
