11

I have a free and paid version of my app in the app store. I'm updating the app to share some public data using CloudKit. I'd like both the free and paid apps to share the same data.

Firstly is it possible for two apps to share the same data with CloudKit?

If so, how can I get this to work? I've tried enabling CloudKit in the capabilities of both targets and selecting the same container in both apps. The main app which has 'Use default container' selected works fine, but the other app, on which I've selected 'Specify custom containers' and selected the custom container from the first target, gets an error back when I try to download anything.

Mark Bridges
  • 8,228
  • 4
  • 50
  • 65

1 Answers1

28

Yes, multiple apps can use the same CloudKit data. When you get your CKContainer, I assume you are using something like the following for both apps?

let container = CKContainer.defaultContainer()

This would work for the main app (the one with the bundle identifier that matches the cloudkit identifier). The other app(s) will need to initialize the container like so:

let container = CKContainer(identifier: "iCloud.com.example.appname")
lehn0058
  • 19,977
  • 15
  • 69
  • 109
  • Thanks. I've got this working by declaring the identifier explicitly in both targets. – Mark Bridges Nov 02 '15 at 15:58
  • Do I need to enable app groups in the capability pane? – Ben Lu Feb 26 '16 at 01:13
  • No, app groups are used to share files between apps. You will need to enable the iCloud container in the capabilities pane for each app. – lehn0058 Feb 26 '16 at 03:10
  • Is it possible to use any identifier for the common container ? I have three apps, and App1 and App2 should share one container and App1, 2 and 3 should share another container. – Colas May 07 '16 at 20:59