How to add events in iPhone using Event Kit framework

随声附和 提交于 2019-12-17 10:47:25

问题


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.



来源:https://stackoverflow.com/questions/6530687/how-to-add-events-in-iphone-using-event-kit-framework

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!