6

我正在尝试构建一个将事件添加到 IOS 7 中的默认日历的应用程序。首先我添加了一个框架:EventKit.Framework 并将其导入我的 .m

这是我的代码:

    - (void)AddEventToCalendar
{

    EKEventStore *eventStore = [[EKEventStore alloc] init];

    EKEvent *event = [EKEvent eventWithEventStore:eventStore];

    // title of the event
    event.title = @"Event";

    // star tomorrow
    event.startDate = [[NSDate date] dateByAddingTimeInterval:86400]; 

    // duration = 1 h
    event.endDate = [[NSDate date] dateByAddingTimeInterval:90000]; 

    // set the calendar of the event. - here default calendar
    [event setCalendar:[eventStore defaultCalendarForNewEvents]];

    // store the event
    NSError *err;
    [eventStore saveEvent:event span:EKSpanThisEvent error:&err];
}

但是当我在我的 iPhone 上运行它时它给了我这个错误

错误域 = EKCADErrorDomain 代码 = 1013 “操作无法完成。(EKCADErrorDomain 错误 1013。)”

你知道我能做什么吗?

4

2 回答 2

4

First of all, you must initialize your EventStore and then request access to use the user’s Calendar database with the following method:

[yourEventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
    if(granted) {
        // create/edit your event here
}];

See the AppleDocumentation

Hope it helps.

于 2014-02-27T16:15:51.073 回答
3

尝试使用requestAccessToEntity它将解决您的问题。

于 2013-12-02T09:40:53.540 回答