EKEvent 事件标识符返回 null
当我尝试获取 EKEvent 的标识符时,我得到的只是一个 nil 值。由于在 iOS5 中 EKEvent 是 EKCalendarItem 的子类,因此我想我也许能够获取 EKCalendarItem 的 UUID,但它也会返回 nil。
我时不时地在尝试访问标识符或 UUID 属性时也会遇到此错误:
CADObjectGetInlineStringProperty failed fetching uniqueID for EKPersistentEvent with error Error Domain=NSMachErrorDomain Code=268435459 "The operation couldn’t be completed. (Mach error 268435459 - (ipc/send) invalid destination port)"
我已经在这个问题上停留了很长一段时间了,但我认为它与 iOS5 beta 相关。但由于我们现在已经是 iOS5,它仍然无法工作。
When I try to get the identifier of an EKEvent, all I get is a nil value. Since in iOS5 EKEvent is a subclass of EKCalendarItem, I figured I might be able to get the EKCalendarItem's UUID, but that returns nil as well.
Every now and then I also get this error while trying to access the identifier or UUID property:
CADObjectGetInlineStringProperty failed fetching uniqueID for EKPersistentEvent with error Error Domain=NSMachErrorDomain Code=268435459 "The operation couldn’t be completed. (Mach error 268435459 - (ipc/send) invalid destination port)"
I've been stuck on this problem for quite some time now, but figured it would be iOS5 beta related. But since we're now at iOS5, it's still not working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
在我的应用程序中,我发现如果您在获取 eventIdentifier 的 eventStore 已释放时请求 eventIdentifier,它将返回 nil。但如果您之前询问 eventIdentifier,它会返回 id 确定。然后,您可以释放 EKEventStore 实例并毫无问题地请求标识符......似乎它需要 eventStore 来检索 id,但我没有收到任何警告。
In my app I found out that if you ask for the eventIdentifier when the eventStore that fetched it has been released, it returns nil. But if you ask for the eventIdentifier before it will return the id ok. You can then release the EKEventStore instance and ask for the identifier with no problem.... Seems that it needs the eventStore to retrieve the id, but I get no warnings.
尝试在检索标识符之前保存并提交您的事件:
Try to save AND commit your event before retrieving the identifier :
eventIdentifier 在事件添加到 EKEventStore 时设置。如果您在添加该值之前尝试访问该值,它将返回 null。
eventIdentifier is set when the event is added to the EKEventStore. If you try to access this value before adding it, it would return null.
刚刚解决这个问题,结果
eventIdentifier
在提交到数据库之前将为空,所以你需要在 saveEvent 函数中有一个 commit:
YES
[self.eventStore saveEvent:event span:EKSpanThisEvent commit:YES error:&error];
之后,你可以获取事件标识符。
我的错误是传递了一个 NO to commit: 参数。
Just going through this problem, turnout the
eventIdentifier
will be null before commit to database,so you need a commit:
YES
in the saveEvent function[self.eventStore saveEvent:event span:EKSpanThisEvent commit:YES error:&error];
After that, you can get the eventIdentifier.
My fault was pass a NO to commit: parameter.
对我来说,
eventIdentifier
为 null,因为我没有设置endDate
。因此,如果创建该事件时出现任何错误,通常eventIdentifier
可能为 null。您可以检查如下错误:For me, the
eventIdentifier
is null because I was not setting theendDate
. So generally theeventIdentifier
can be null if there are any error on creating that event. You can check for errors like this:在保存事件之前,不会生成 EKEvent eventIdendifier。将事件保存到 EKEventStore 后,您可以访问/存储 eventIdentifier
The EKEvent eventIdendifier isn't generated until the event is saved. You can access/store the eventIdentifier after you've saved the event to the EKEventStore
对于 Swift 3,
我发现问题在于我在检索日期的函数中创建了存储。
在函数外部创建存储并使用其实例解决了这个问题。
For Swift 3
I have found out, that the issue was that I have created the store within the function that retrieves the date.
Creating the store outside of the function and using its instance solved the issue.