gpt4 book ai didi

objective-c - 使用我的应用程序将事件添加到日历 IOS7

转载 作者:太空狗 更新时间:2023-10-30 03:42:41 27 4
gpt4 key购买 nike

我正在尝试构建一个可以将事件添加到 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 上运行它时它给了我这个错误

Error Domain=EKCADErrorDomain Code=1013 "The operation couldn’t be completed. (EKCADErrorDomain error 1013.)"

你知道我能做什么吗?

最佳答案

首先,您必须初始化您的 EventStore,然后通过以下方法请求访问以使用用户的日历数据库:

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

参见 AppleDocumentation

希望对您有所帮助。

关于objective-c - 使用我的应用程序将事件添加到日历 IOS7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19316561/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com