How sync events on iOS with EventKit across multiple devices
calendarItemExternalIdentifier
is available as soon as you save (with commit) a calendar item. But, there are situations when the calendarItemExternalIdentifier
is later changed, when the calendar item is synced further to the server (e.g. if it's an event from an Exchange account).
All the other identifiers are not shared between devices (this includes identifiers for sources and calendars), so the best option is sticking with calendarItemExternalIdentifier
.
A full sync with a calendar can occur when the user sets up a new source (e.g. the user removes and adds the same Exchange account). There may also be different situations that cause a full calendar sync.calendarIdentifier
is a local identifier, so it won't be of much use in your case (except if you want to create a workaround for the issue with calendarItemExternalIdentifier
changing).
As mentioned earlier, the calendar and source identifiers are not global, so it would be near impossible to know if "Foo" calendar is setup on a different device, or if the "Foo" calendar is the same "Foo" calendar from your other device.
Usually, if you find your Action object on the new device, you can assume that the calendar that it belongs to is the same as the calendar from the different device.
One way to go about it, when updating your Action objects, would be to save the changes (as usual) to the server. Each of the devices (including the one that made the change) would then search for the corresponding calendar item, and update it if it's found.
I'm currently doing something similar, and this is probably what I'll end up doing.
A better alternative (probably more time consuming as well) would be to have the server connect and sync with the external sources (CalDav, Exchange etc.).
EKEvent with eventWithIdentifier on iOS
I am using newEvent.eventIdentifier
instead of newEvent.calendarItemIdentifier
and so far, using [store eventWithIdentifier:_project.event_identifier]
, I can retrieve, delete and edit an existing event. you should try.
How to properly identify an ical event
If you are using iOS 6 try calendarItemExternalIdentifier.
This identifier allows you to access the same event or reminder across multiple devices.
I had this problem using core data, iCloud and calendars. I captured the eventIdentifier and saved it to core data on one device BUT when I checked the other device the eventIdentifier had changed on the calendar.
Resolved it by capturing the calendarItemExternalIdentifier instead of the eventIdentifier:
iOS Reference
Capture the calendarItemExternalIdentifier when saving the event:
- (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]];
.......
When displaying event in the app, query if an event is one of our "session" events :
// 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
}
Setting the URL field of an EKEvent
I'm guessing you're on iOS 5 Beta? EKEvents
shouldn't have a URL property pre-5.0
Take a look at EKCalendarItem
on the 5.0 SDK. EKEvent
is being phased out, and it's superclass changed from NSObject
to EKCalendarItem
.
EKCalendarItem has the @property(nonatomic, copy) NSURL *URL
Related Topics
How to Force My Keyboard to Be Up on My Program's Start in Swift
React Native Change Default iOS Simulator Device
Cllocationmanager and Accuracy Issues - Any Experiences
Uinavigationcontroller Without Navigation Bar
Using Enum as Property of Realm Model
New React Native Project with Old Version of React Native
How to Compare Two Strings Ignoring Case in Swift Language
Filenames Are Used to Distinguish Private Declarations of the Same Name' Error
How to Add Done Button on Keyboard on Top of Keyboard in iOS
How to Return Value After the Execution of the Block? Swift
iPad Multitasking Support Requires These Orientations
Change Uitextfield and Uitextview Cursor/Caret Color
How to Change Label Constraints During Runtime
How to Distribute iOS Applications Outside App Store
Icon Already Includes Gloss Effects
Setting Alpha on Uiview Sets the Alpha on Its Subviews Which Should Not Happen