Search code examples
iosiphonexcodecloudkitwatchos-3

iCloud uses a different container on watchOS 3


I'm trying to get iCloud to work between iPhone and the Apple Watch (using CloudKit on watchOS 3). I have specified the cloud container in the Watch Extension to be the same as the one in the iOS target, but when running the app, I get this error from a query I made:

Failure retrieving: Optional(<CKError 0x17d45cf0: "Unknown Item" (11/2003); server message = "did not find record type recordTypeId="Recommendation""; uuid = 37D53C78-FF19-4CE3-80BD-C1990F0135A2; container ID = "iCloud.mathsrobot.MathsRobot-LearnMaths.watchkitapp.watchkitextension">)

From the container ID, I can tell that it is not using the iOS app container, which should be iCloud.mathsrobot.MathsRobot-LearnMaths. How can I make it use the iCloud container for the iOS app?

iOS target capabilities screenshot Main iOS target capabilities with iCloud

Watch target capabilities screenshot Watch Extension target capabilities with iCloud


Solution

  • Most likely you are using the default container in your code ...

    container = CKContainer.default()
    

    Which will default to the watchOS app's container ID, even if you set it in Xcode. You should try to do something like this ...

    container = CKContainer(identifier: "iCloud.mathsrobot.MathsRobot-LearnMaths")