I am making a Restaurant application in which i need to add events in calendar, events information are coming from server, if client add any event it should show in calendar for that specified date, i have used event kit frame work and successfully added one event into the calendar, however how to add multiple events in calendar using event kit.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
First of All, Add EventKit Framework and import it in .h file. Like below.
#import <EventKit/EventKit.h>
See Below Function and Modify it as per your need.
-(IBAction)AddEvent:(id)sender{
EKEventStore *eventSotre = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:eventSotre];
if([txtTitle.text isEqualToString:@""] || txtTitle.text == NULL)
txtTitle.text=@"Event Title";
event.title= txtTitle.text;
NSDate *duedate = pkrDate.date;
event.startDate =duedate;
event.endDate= [[NSDate alloc] initWithTimeInterval:600 sinceDate:duedate];
if(switchAlarm.on==TRUE){
NSArray *arrAlarm = [NSArray arrayWithObject:[EKAlarm alarmWithAbsoluteDate:duedate]];
event.alarms= arrAlarm;
}
[event setCalendar:[eventSotre defaultCalendarForNewEvents]];
NSError *err;
BOOL isSuceess=[eventSotre saveEvent:event span:EKSpanThisEvent error:&err];
if(isSuceess){
UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"Event" message:@"Event added in calendar" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertview show];
[alertview release];
}
else{
UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"Event" message:[err description] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertview show];
[alertview release];
}
[eventSotre release];
}
Please modify it as per your need. I just paste it from my one of app code.