Search code examples
iphonecore-dataios5icloud

Icloud Sync between 2 app having different app identifier


I have an app which has different app identifier for iphone and ipad and i want to sync both of them using icloud, is it posible to use different app identifer for same container in icloud.


Solution

  • Yes, it is possible to sync data between different apps using iCloud (different apps always have different app IDs, don't they?). Use the entitlements of your apps to specify to which containers they should have access. Then use a common container to store and sync your files.

    Update on 10/30/2013 on request of Dinesh Kaushik:

    • Open your project in Xcode and select the project in the ProjectNavigator
    • Go to the "Capabilities" Tap (Xcode 5) of the project and find the iCloud section (should be right on the top)
    • Here you can specify all Ubiquity Container the app should have access to.
    • To share data between apps they need to share a common Ubiquity Container. Thus add at least one Ubiquity Container that is used by all participating apps. The easiest way to just one Ubiquity Container (of course the same in each app)
    • When "connecting" to iCloud you use the following code to get the Ubiquity URL:

      NSURL *cloudURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];

    • Using nil as identifier will return the URL of the default Ubiquity Container. Use a concrete ID to get the URL of another Ubiquity Container.

    The Ubiquity Container is basically just a folder on your device. The iCloud Service will observe this folder and transfer all changes to the same folder on other devices.

    From my experience there is one golden rule about iCloud:

    DONT USE IT!

    I am serious. iCloud is unstable and unreliable. Your app might crash from time to time and you will never find out the concrete source of the problem. Users will ask why syncing does not work from time to time and blame you and your app for the poor performance.

    iCloud might be OK for simple KeyValueStore but anything else is a mess. Do not wast your time. Use another Cloud service like Dropbox instead.