有没有办法在iCal中添加标识符或标记自定义事件?

时间:2011-02-18 06:49:13

标签: iphone calendar icalendar eventkit reminders

我正在我的应用中设置提醒。我已使用EKEventiCal添加了自定义事件。现在,当我从iCal检索事件时,我得到了当天发生的所有事件。有没有办法获取/检索仅通过我的应用程序添加的事件,我尝试了eventIdentifier的{​​{1}}属性,但它是一个只读属性。 有人可以帮忙???

2 个答案:

答案 0 :(得分:3)

您可以遍历与特定日期匹配的所有日历事件,但这不是首选方法。每个事件都使用唯一的eventIdentifier属性创建。保存事件时,您可以复制eventIdentifier,下次要修改该特定事件时,可以使用EKEventStore eventWithIdentifier方法加载事件。

示例可能如下所示

   EKEventStore *eventStore = [[EKEventStore alloc] init];
   NSError *err;
   EKEvent *event  = [EKEvent eventWithEventStore:eventStore];
   //modify all the event properties you would like then save
   [eventStore saveEvent:event span:EKSpanThisEvent error:&err];
   self.calendarEventID = event.eventIdentifier; 
   [eventStore release];

稍后,如果您想从之前的代码中检索已保存的事件,则可以执行以下操作

   //self.calendarEventID is a NSString property declared in the .h file and synthesized in .m
   EKEvent *myEvent = [eventStore eventWithIdentifier:self.calendarEventID];

答案 1 :(得分:1)

未完善:

我在设置iCal警报时使用的AppleScript遇到了类似的问题;我希望能够识别并删除我的脚本在下一次传递中所做的事件。

我找不到iCal事件的任何类似标签的属性,所以我最终使用了location属性,这是一个字符串;我把它设置为“”并搜索它。 (警告:警报消息包括最后的位置,被parens包围,所以这会让事情变得有点过时。)

如果您的应用中需要location属性用于其他目的,您仍然可以添加一些识别字符序列。或者也许你可以使用其他你不需要的其他财产。

相关问题