3

我正在探索 EKEventKit。我连接我的 iPhone 并拨打电话以安装日历

EKEventStore *eventDB = [[EKEventStore alloc] init];
NSArray * calendars = [eventDB calendars ];

但是,当我记录日历时,我收到此错误消息

“CADObjectGetIntProperty 失败,出现错误 Error Domain=NSMachErrorDomain Code=268435459 “操作无法完成。(马赫错误 268435459 -(ipc/send)无效的目标端口)”

有谁知道这是什么以及为什么我得到它。谢谢

礼萨

4

4 回答 4

8

我发现了这个问题。

我之前在我的代码中加载并保留了一个 EKEventStore。删除其中一个解决了问题

礼萨

于 2012-07-10T13:28:18.920 回答
2

我的控制台上有相同的警告日志

之前的代码:

"CalendarEventHandler.m"
eventStore = [[EKEventStore alloc] init];


"CalendarEventHandler.h"

@property (nonatomic,strong) EKEventStore *eventStore;

代码修改

self.eventStore = [[EKEventStore alloc] init];//This helped me to remove warning
于 2013-03-07T07:21:47.030 回答
2

@discussion 到EKEventStoreEKEventsStore.h文件说:

"It is generally best to hold onto a long-lived instance of an event store, most likely as a singleton instance in your application."

这里也写了同样的内容:Reading and Writing Calendar Events,在Connecting to the Event Store部分:

"An EKEventStore object requires a relatively large amount of time to initialize and release. Consequently, you should not initialize and release a separate event store for each event-related task. Instead, initialize a single event store when your app loads, and use it repeatedly to ensure that your connection is long-lived."

所以正确的做法是:

@interface MyEventStore : EKEventStore

+ (MyEventStore *)sharedStore;

@end

+ (MyEventStore *)sharedStore
{
    static dispatch_once_t onceToken;
    static MyEventStore *shared = nil;
    dispatch_once(&onceToken, ^{
        shared = [[MyEventStore alloc] init];
    });
    return shared;
}

@end

并使用它调用[MyEventStore sharedStore].

这种方法还修复了警告。

于 2014-03-06T16:24:59.650 回答
0

将实例 'eventDB' 设为类成员变量或属性可以解决问题。

于 2015-06-19T11:16:33.137 回答