在 iOS 中,EKEvent 类有 2 个关于事件标识符的属性:eventIdentifier 和 uuid 属性。在 Mac 上的 ical 上查看相同的同步事件时,CalEvent 有一个 uid 属性,但在我的测试中这些都不匹配。
有人知道如何正确识别双方的事件吗?
如果您使用的是 iOS 6,请尝试使用 calendarItemExternalIdentifier。
This identifier allows you to access the same event or reminder across multiple devices.
我在使用核心数据、iCloud 和日历时遇到了这个问题。我捕获了 eventIdentifier 并将其保存到一个设备上的核心数据,但是当我检查另一个设备时 eventIdentifier 在日历上已更改。
通过捕获 calendarItemExternalIdentifier 而不是 eventIdentifier 来解决它:
iOS Reference
在保存事件时捕获 calendarItemExternalIdentifier:
- (void)eventEditViewControllerEKEventEditViewController *)controller
didCompleteWithActionEKEventEditViewAction)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]];
.......
在应用中显示事件时,查询事件是否是我们的“ session ”事件之一:
// 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
}
关于ios - 如何正确识别 ical 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8426960/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |