将事件添加到iphone日历

时间:2017-01-13 10:35:11

标签: ios objective-c calendar ekeventkit

我正在使用SAcalendar。 这是我的json:

{-data: - [
- {
id: "1",
event_start: "2014-06-09 11:30",
event_end: "2014-06-09 12:30",
title: "Click a date to create a new event and drag to change its     date and time. Click on an existing event to modify. Click "Show Standard     Settings" to set additional event properties."
},
- {
id: "2",
event_start: "2017-01-03 16:30",
event_end: "2017-01-03 17:30",
title: "fgdgf"
},
- {
id: "3",
event_start: "2017-01-11 03:30",
event_end: "2017-01-11 06:00",
title: "fdfgdg"
},    ]}

现在我想将这些事件添加到我的日历中  这是我的代码(使用EventKit的代码相同)

EKEventStore *store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL     granted, NSError *error) {
if (!granted) { return; }
EKEvent *event = [EKEvent eventWithEventStore:store];
event.title = @"Event Title";
event.startDate = [NSDate date]; //today
event.endDate = [event.startDate dateByAddingTimeInterval:60*60];  //set 1 hour meeting
[event setCalendar:[store defaultCalendarForNewEvents]];
NSError *err = nil;
[store saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
NSString *savedEventId = event.eventIdentifier;  //this is so you can access this event later    

它会显示任何事件。 我是ios的新手,请帮忙.. 提前谢谢。

0 个答案:

没有答案