So my question is as written in the title if you could use NSPersistentCloudKitContainer to share data between different apps like if you have a different app for iPad, a different one for iPhone and a different one for Mac and if possible how would you do that? Thanks in advance!
1 Answers
Yes, you can, even across different platforms (macOS, iOS). I have done that several times, actually. All it takes is the same iCloud bundle ID. Click on Capability to select iCloud. Turn on the CloudKit checkbox button. Then select a specific bundle ID below.
If you are going to use the same cloud container, you must be careful with the data types you use. For example, you shouldn't save UIImage or NSImage there because they are not exactly compatible with each other. In this case, you should save an image as Data
.
Addition
When you want to use a specific cloud container other than the (default) one that your project has automatically created, make sure you specify it in accessing the cloud database. That's the same for macOS and iOS.
let cloudContainer = CKContainer(identifier: "iCloud.com.tomato.Eltomato")
let publicDB = cloudContainer.publicCloudDatabase

- 6,479
- 6
- 46
- 75
-
Thanks. El Tomato. Do you know if you can share the private data amount different apps using NSPersistentCloudKitContainer (the same apple id, but the apps are from same developers for the same user) – Emmy Apr 05 '20 at 22:07
-
@Emmy I don't understand what you mean by sharing the private data amount. But isn't it the matter of sharing the same cloud container ID like "iCloud.com.tomato.Eltomato?" – El Tomato Apr 06 '20 at 00:25
-
I figure it out. I have more than one apps that allow the users to add students to the apps. The apps can share the same students info amount each other. all the apps use the same cloud container id which you can setup in Xcode cloud configuration. – Emmy Apr 06 '20 at 02:21