iCloud 在 watchOS 3 上使用不同的容器

the*_*bot 3 iphone xcode ios cloudkit watchos-3

我正在尝试让 iCloud 在 iPhone 和 Apple Watch 之间工作(在 watchOS 3 上使用 CloudKit)。我已将 Watch Extension 中的云容器指定为与 iOS 目标中的云容器相同,但是在运行该应用程序时,我从我所做的查询中收到此错误:

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">)
Run Code Online (Sandbox Code Playgroud)

从容器 ID,我可以看出它没有使用 iOS 应用程序容器,应该是iCloud.mathsrobot.MathsRobot-LearnMaths. 如何让它为 iOS 应用程序使用 iCloud 容器?

iOS 目标能力截图 iCloud 的主要 iOS 目标能力

观看目标功能截图 使用 iCloud 观看扩展目标功能

Tac*_*che 7

很可能您在代码中使用了默认容器......

container = CKContainer.default()
Run Code Online (Sandbox Code Playgroud)

这将默认为 watchOS 应用程序的容器 ID,即使您在 Xcode 中设置它。你应该尝试做这样的事情......

container = CKContainer(identifier: "iCloud.mathsrobot.MathsRobot-LearnMaths")
Run Code Online (Sandbox Code Playgroud)