Database Reference
In-Depth Information
6.8
Sharing Data Between iOS and OS X
So far, we have discussed sharing data between iOS devices and linking our
OS X application to iCloud. However, we have not discussed how to share
data between OS X and iOS. Fortunately, there is virtually no difference
between OS X and iOS iCloud integration, though there are a couple of rules
that we need to follow.
The Content Name Key Must Be the Same
The NSPersistentStoreUbiquitousContentNameKey is the unique value that iCloud uses
to determine what data we are accessing. If two devices use the same value
and are signed by the same developer, they will be able to access the same
data. If one or more devices and one or more OS X machines use the same
key, they will share the same data.
Throughout these examples, we have been using the value [[NSBundlemainBundle]
bundleIdentifier] . There is nothing wrong with using that value, so long as all of
our applications are using the same bundle identifier. However, if they are
not, then we must use a different string to serve as this key. Apple recom-
mends a reverse DNS notation style, and I certainly see no reason to suggest
otherwise.
The Data Model Must Be the Same
Core Data is virtually identical between iOS and OS X. We can use the same
data model, even the same file, between OS X and iOS. iCloud expects and
requires us to do exactly that. If the data models do not match, the transaction
logs cannot be played back properly, and the synchronizing fails. The easiest
way to ensure this is to share the data model (and the entity subclasses)
between the OS X application and the iOS application. This step guarantees
the applications are using the same model.
However, additional care must be taken when upgrading the model. If we
release an update to our iOS application but not our OS X application, they
can become out of sync, and iCloud integration will stop working. Once the
first device with a new model touches iCloud, iCloud works only with devices
that are using the updated model. Any device using the older model simply
stops working with iCloud. Fortunately, as soon as the out-of-date machine
updates to the latest model, iCloud starts working again.
The best way to test iCloud syncing is to have more than one application
running at the same time that uses the data. We could run our existing
application on an iPhone and an iPad to see the syncing work, but watching
 
 
Search WWH ::




Custom Search