PartialQueryGuy PartialQueryGuy - 1 year ago 93
iOS Question

Two apps sharing two CloudKit CKContainers: Need both UserRecordIDs

I have one app that uses it's own native CKContainer. I am building a second app that uses the first app's native CKContainer and it's own native container as well. I would like to access both container's userID using the function below. However, I am only getting back the second app's native CKContainer UserID. I am successfully using the public database of the first app in the second app. I am only struggling when I try to perform a query specific to the user in the first app.

Does anyone know if this is possible and/or how to find a second CKContainer's userID?

func findUserRecordID() {
CKContainer.defaultContainer().fetchUserRecordIDWithCompletionHandler { (userID, error) -> Void in
if error == nil {
// obtain and store id
if let userID = userID {

SRData.sharedInstance.currentUser = userID

} else if error != nil {
// handle errors

print("There was an error" + "\(error?.localizedDescription)")

Answer Source

You need two CKContainer instances, one for each container. The two containers are not shared. Each has its own public database, its own private database, and its own users.

To create the other container, use:

CKContainer(containerIdentifier: "the-name-of-the-other-container")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download