我正在制作一个餐馆应用程序,其中我需要在日历中添加事件,事件信息来自服务器,如果客户端添加它应该在日历中显示的指定日期,我已经使用事件工具包框架工作并成功在日历中添加了一个事件,但是如何使用事件工具包在日历中添加多个事件。
答案 0 :(得分:20)
首先,添加EventKit Framework并将其导入.h文件中。如下所示。
#import <EventKit/EventKit.h>
请参阅下面的功能并根据需要进行修改。
-(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];
}
请根据您的需要进行修改。我只是从我的应用代码中粘贴它。