iOS 应用程序不会使用自定义 iCloud 容器

Jor*_*416 2 xcode containers ios icloud cloudkit

因此,我正在开发两个要使用同一个 iCloud 容器的应用程序。

我已经按照 Xcode 和苹果的在线文档中所示的所有步骤进行操作。我在我的应用程序中添加了激活的 iCloud 功能,选中了 CloudKit 复选框,选择了一个我想要使用的自定义容器(这两个应用程序显然相同)。

该应用程序已更改权利文件中的 iCloud 容器标识符,这应该表明一切正常。但是,每当我使用该应用程序并打印我的容器名称时,它都会显示每个应用程序的默认容器名称。

对于这两个应用程序,功能屏幕如下所示: 在此处输入图片说明

我创建了一个对象,CloudKitController用于管理所有云流量。我将它初始化为应用程序启动的超时时间,并设置如下变量:

var container:      CKContainer
var publicDB:       CKDatabase
let privateDB:      CKDatabase
var delegate:       CloudKitControllerDelegate?

override init() {
        container = CKContainer.default()
        print(container.containerIdentifier)
        //this prints the name of the default container for the project
        publicDB = container.publicCloudDatabase
        privateDB = container.privateCloudDatabase
    }
Run Code Online (Sandbox Code Playgroud)

我什至访问了开发人员门户并确保我要使用的容器是两个应用程序都关联的唯一容器。也没有用。

我的问题是:我怎样才能让两个应用程序(显然来自同一个开发人员帐户和配置文件)在一个 iCloud 容器上运行?

rma*_*ddy 6

您表示您希望使用具有特定标识符的特定容器。但是您拥有的代码是专门访问应用程序的默认容器。那不是你想要的。

改变:

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

到:

container = CKContainer(identifier: "your shared container id")
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请阅读CKContainer该类的文档。