如何使用Event Kit框架在iPhone中添加事件 [英] How to add events in iPhone using Event Kit framework

查看:239
本文介绍了如何使用Event Kit框架在iPhone中添加事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个餐馆应用程序,其中我需要在日历中添加事件,事件信息来自服务器,如果客户端添加它应该在日历中显示的指定日期,我已经使用事件工具包框架工作并成功在日历中添加了一个事件,但是如何使用事件工具包在日历中添加多个事件。

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.

推荐答案

首先,添加EventKit框架并将其导入.h文件中。如下所示。

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.

这篇关于如何使用Event Kit框架在iPhone中添加事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆