iPhone:如何检测 EKEvent 实例是否可以修改?
在 iPhone 上使用 EventKit 时,我注意到有些事件可能存在且无法修改。到目前为止,我遇到的例子是与 CalDAV 同步的生日和事件。当您在 iPhone 上的标准内置日历应用程序中查看事件的详细信息时,右上角的“编辑”按钮在这些情况下不可见,而在查看“正常”事件时则可见。
我到处搜索,阅读所有文档,但我根本找不到任何告诉我如何检测这种行为的内容!我只能事后检测它:
- 编辑事件的标题
- 将其保存到事件存储
- 检查事件的标题,如果没有更改,则不可编辑!
我正在寻找一种可以提前检测事件的不可编辑行为的方法。我知道这是可能的,因为我已经看到其他日历应用程序正确地实现了这一点。
While working with the EventKit on iPhone I noticed that some events can exist which cannot be modified. Examples I encountered so far are birthdays and events synced with CalDAV. When you view the event's details in the standard built-in calendar app on iPhone the "Edit" button in the top-right corner is not visible in these cases, where it would be visible when viewing "normal" events.
I've searched everywhere, read all documentation there is but I simply can't find anything that tells me how to detect this behavior! I can only detect it afterwards:
- edit an event's title
- save it to the event store
- check the event's title, if it has not changed it is not editable!
I am looking for a way that I can detect the non-editable behavior of an event beforehand. I know this is possible because I've seen other calendar apps implement this correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
好吧,看来 SDK 没有为我提供任何可用于检查 EKEvent 是否为只读的内容。我通过创建一个类别来创建一个解决方法,该类别向所有 EKEvent 实例添加“isReadOnly”方法。
EKEvent+ReadOnlyCheck.h
EKEvent+ReadOnlyCheck.m
当上述文件就位后,我可以简单地对我选择的 EKEvent 调用
isReadOnly
。Ok it appears as if the SDK doesn't provide me with anything I can use to check if an EKEvent is read-only. I created a workaround by creating a category that adds an "isReadOnly" method to all EKEvent instances.
EKEvent+ReadOnlyCheck.h
EKEvent+ReadOnlyCheck.m
When the above files are in place I can simply call
isReadOnly
on the EKEvent of my choice.我还没有使用过 Event Kit,但从文档来看,可编辑性似乎是日历的属性,而不是事件的属性。
event.calendar
获取事件的日历,calendar.allowsContentModifications
告诉您日历是只读还是读写。I haven't worked with Event Kit yet, but from the documentation it seems that editability is a property of a calendar, not of an event.
event.calendar
gets you the event's calendar, andcalendar.allowsContentModifications
tells you if the calendar is read-only or read-write.在显示视图之前尝试 EKEventViewController 的 allowedEditing 属性。
try allowsEditing property of EKEventViewController before displaying the view.
是的。这是可能的。代码如下所示:
尝试通过记录我与可编辑/不可编辑事件一起使用的对象的输出来与代码相关,您将了解其工作原理:)
Yes. It is possible. The code would look like following :
Try relating to code by logging the output of objects I use with editable/non editable events and you will understand the working:)
我认为为 EKEvent 添加此类别方法可以处理事件不可编辑的所有情况:
I think adding this category method for
EKEvent
handles all cases where events are not editable: