How to add events in iPhone using Event Kit framework

后端 未结 1 1473
醉话见心
醉话见心 2020-12-03 02:21

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

相关标签:
1条回答
  • 2020-12-03 02:54

    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.

    0 讨论(0)
提交回复
热议问题