Question

I have an app that is syncing Core Data to iCloud. It seems to be working fine, whether or not I made a call to URLForUbiquityContainerIdentifier:.

Is a call to URLForUbiquityContainerIdentifier: needed in all cases? (that would help me not to call it if useless).

More details, as requested by Tom :

I am not doing anything with the result of URLForUbiquityContainerIdentifier: (which is the URL of the default app container, as I call with "nil" as argument). I was just following Apple's documentation that states

Although the ubiquityIdentityToken method tells you if a user is signed in to an iCloud account, it does not prepare iCloud for use by your app. In iOS, make your ubiquity containers available by calling the NSFileManager method URLForUbiquityContainerIdentifier: for each of your app’s ubiquity containers.

So this is exactly what I do.

But I don't see any effect on Core Data synchronisation if I don't do that (in clear, if I don't do that, Core Data still syncs pretty well - or at least seems to).

So I was wondering for other people's experience. If that call is not needed (for example because Core Data might manager its own container by itself), then it is better to forget it. As it has to be done from a background thread, this makes a lot of code for nothing.

Was it helpful?

Solution

The documentation you cite is out of date for iOS 7, which included numerous internal changes to Core Data's iCloud system. Among them is that when you call addPersistentStoreWithType:configuration:URL:options:error: with iCloud keys in the options dictionary, it internally calls URLForUbiquityContainerIdentifier: for you. As a result, calling this method yourself isn't normally necessary if you're only using iCloud with Core Data.

If you're still supporting iOS 6 (not recommended if you're also using iCloud) then you'll need to call URLForUbiquityContainerIdentifier: yourself.

For more details on Core Data + iCloud changes in iOS 7, I recommend WWDC 2013 session 207, "What's New in Core Data".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top