Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing non-default Cloudkit container with Swift

I have an IOS 8 App which is successfully writing out records to its default Cloudkit container. Now I wish to read and process those records in a different App under OS X. I have set up the new App with iCloud access and with the "specify Custom Containers' option checked. This is successfully found the container of the original App and I have no errors to be fixed on the Capabilities interface.

All my searching tells me that "It is possible that two apps signed by the same developer share the same container" but none of the tutorial documents that I can find tell me how to access the data from a custom container. All the examples seem to begin with 'let container = CKContainer.defaultContainer()'. However, I don't want to access records from the default container. I want the custom container.

The Apple documentation suggests using an init() structure but that has me baffled also. It seems like a simple request. Hopefully someone can give me a simple solution.

like image 838
Ian Bishop Avatar asked Jul 03 '15 06:07

Ian Bishop


1 Answers

This is untested code, but what I understand about it is that custom containers allow you to share these containers across multiple apps. In the Capabilities pane, you can choose which of all containers available in all your other apps you choose to use in this app. The default container is iCloud.com.MyCompany.MyApp, which should be automatically selected. Now that you have specified which containers you want, you can access them my using the init()

let container = CKContainer(identifier: "iCloud.com.MyCompany.OneOfMyApps")

Basically, the identifier is one of the identifiers listed in iCloud Capabilities pane under custom containers.

like image 89
imas145 Avatar answered Oct 29 '22 15:10

imas145