简体   繁体   English

选择其他日历时,EKEvent标识符会更改

[英]EKEvent identifier changes when selecting another calendar

I have a meeting planner app that has its own sqlite database and attaches it self to an EKEvent from the calendar framework. 我有一个会议策划应用程序,它有自己的sqlite数据库,并将其自身附加到日历框架的EKEvent。 I'm using the event identifier as a foreign key for my meeting data. 我正在使用事件标识符作为会议数据的外键。 The problem resides when a user changes the event's calendar in the calendar application. 当用户在日历应用程序中更改事件的日历时,问题就出现了。 The identifier changes and I got no way of knowing that it changed since it was made outside my app. 标识符更改,我无法知道它已更改,因为它是在我的应用程序之外。 Please let me know if anyone has any ideas 如果有人有任何想法,请告诉我

从iOS 5.0开始,无法确定地唯一标识事件

The documentation warns that "If the calendar of an event changes, its identifier most likely changes as well." 文档警告说“如果事件的日历发生变化,其标识符很可能也会发生变化。”

Another gotcha is that all instances of a repeating event have the same identifier; 另一个问题是重复事件的所有实例都具有相同的标识符; -[EKEventStore eventWithIdentifier:] seems to return the first instance. -[EKEventStore eventWithIdentifier:]似乎返回第一个实例。 (I've even seen events with a nil identifier; I can't remember what the exact cause is.) (我甚至看到过带有nil标识符的事件;我不记得究竟是什么原因。)

If -eventWithIdentifier: returns a non-repeating event, then you're probably good to go. 如果-eventWithIdentifier:返回一个非重复的事件,那么你可能会很高兴。 Otherwise, the easiest way around both of these is probably to search all calendars for events at around the same time and use a heuristic to determine the best match, or ask the user to pick the corresponding event if none of the matches are good enough. 否则,解决这两个问题的最简单方法可能是在大约同一时间搜索所有日历中的事件并使用启发式方法来确定最佳匹配,或者如果没有匹配项足够好,则要求用户选择相应的事件。

You might also want to check what Google Calendar does when you edit a single instance of a repeating event (it might create an event with a new identifier and add a "hole" in the original event's repeat information, which may break your heuristic). 您可能还想检查在编辑重复事件的单个实例时Google日历的功能(它可能会创建一个带有新标识符的事件,并在原始事件的重复信息中添加“漏洞”,这可能会破坏您的启发式)。

我现在正面临这个问题,试图在我的应用程序中保持同步的EventStore与内部数据库,我的解决方案是在应用程序内的EKEvents和事件之间进行映射,如果我发现匹配它没关系但是所有事件都没有将删除与EKEvents匹配的,并且将添加所有不匹配的EKEvents,这样做也会在同步期间添加刚刚被修改的EKEvents。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM