【发布时间】:2011-12-08 06:14:26
【问题描述】:
在 iOS 中,EKEvent 类有 2 个关于事件标识符的属性:eventIdentifier 和 uuid 属性。在 mac 上查看 ical 上的相同同步事件时,CalEvent 有一个 uid 属性,但在我的测试中这些都不匹配。
有人知道如何正确识别双方的事件吗?
【问题讨论】:
标签: ios cocoa-touch cocoa
在 iOS 中,EKEvent 类有 2 个关于事件标识符的属性:eventIdentifier 和 uuid 属性。在 mac 上查看 ical 上的相同同步事件时,CalEvent 有一个 uid 属性,但在我的测试中这些都不匹配。
有人知道如何正确识别双方的事件吗?
【问题讨论】:
标签: ios cocoa-touch cocoa
如果您使用的是 iOS 6,请尝试使用 calendarItemExternalIdentifier。
此标识符允许您跨多个设备访问相同的事件或提醒。
我在使用核心数据、iCloud 和日历时遇到了这个问题。我捕获了 eventIdentifier 并将其保存到一个设备上的核心数据,但是当我检查另一个设备时 eventIdentifier 在日历上已更改。
通过捕获 calendarItemExternalIdentifier 而不是 eventIdentifier 来解决它:
iOS Reference
在保存事件时捕获 calendarItemExternalIdentifier:
- (void)eventEditViewController:(EKEventEditViewController *)controller
didCompleteWithAction:(EKEventEditViewAction)action {
NSError *error = nil;
EKEvent *thisEvent = controller.event;
switch (action) {
case EKEventEditViewActionCanceled:
// Edit action canceled, do nothing.
break;
case EKEventEditViewActionSaved:
{[self.selectedClientSession setEventIdentifier:[thisEvent calendarItemExternalIdentifier]];
.......
在应用中显示事件时,查询事件是否是我们的“会话”事件之一:
// Get the event e.g. from a tableview listing of events today
calendarEvent = (EKEvent*)[eventsList2 objectAtIndex:indexPath.row];
// Is this one of our session events? Build a predicate to query our clientSession objects by comparing the identifier we captured with the Event calendarItemExternalIdentifier
self.sessionPredicate = [NSPredicate predicateWithFormat:@" eventIdentifier = %@ ",[calendarEvent calendarItemExternalIdentifier]
// Get the results
[self setupFetchedResultsController];
//Check that calendarItemExternalIdentifier has been recorded in our session database
NSArray *sessionSet = [self.fetchedResultsController fetchedObjects];
//If no results then this is not a client session
if (sessionSet.count == 0){
// Just a regular event to display
} else{
//It is a client session - display and allow to do interesting stuff
}
【讨论】:
eventWithIdentifier: 和calendarItemExternalIdentifier 吗?
似乎EKEvent 属性eventIdentifier 的后半部分包含CalEvent 属性uid。我不知道eventIdentifier 中的第一个标识符(冒号之前)是什么。它似乎与日历有关,但我不认识标识符。
【讨论】: