Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用相同的CloudKit数据库构建两个不同的应用程序?_Ios_Swift_Cloudkit - Fatal编程技术网

Ios 如何使用相同的CloudKit数据库构建两个不同的应用程序?

Ios 如何使用相同的CloudKit数据库构建两个不同的应用程序?,ios,swift,cloudkit,Ios,Swift,Cloudkit,我需要做的是建立两个不同的应用程序,都在我的开发者帐户下。给用户一个可以查看数据库中的数据,给我一个方便我更改此数据库。我正在使用CloudKit、默认容器和公共数据库 所以我现在尝试的是,我有一个应用程序供用户使用,比如说应用程序名为showdata。在该应用程序中,我使用默认容器和公共数据库,如下所示: let publicDatabase = CKContainer.default().publicCloudDatabase 然后我用它来执行查询: query = CKQuery(rec

我需要做的是建立两个不同的应用程序,都在我的开发者帐户下。给用户一个可以查看数据库中的数据,给我一个方便我更改此数据库。我正在使用CloudKit、默认容器和公共数据库

所以我现在尝试的是,我有一个应用程序供用户使用,比如说应用程序名为showdata。在该应用程序中,我使用默认容器和公共数据库,如下所示:

let publicDatabase = CKContainer.default().publicCloudDatabase
然后我用它来执行查询:

query = CKQuery(recordType: "updateAndHold", predicate: NSPredicate(format: "TRUEPREDICATE"))
publicDatabase.perform(query!, inZoneWith: nil) { (records, error) in
在第二个应用程序中,我们将其命名为updatedata。 我应该如何使用相同的数据库和容器来更新数据。我尝试过以下代码:

let container = CKContainer.init(identifier: "iCloud.com.WMWIOS.showdata").publicCloudDatabase
但当我获取任何记录时,它会给我一个错误,即没有使用该名称的权限:

query = CKQuery(recordType: "updateAndHold", predicate: NSPredicate(format: "TRUEPREDICATE"))
container.perform(query!, inZoneWith: nil) { (records, error) in
当我打印PublicDatabase和printcontainer时,它有不同的ID,但有相同的标识符


我需要帮助解决这个问题。如果您需要更多信息,请告诉我。

此代码使用命名的icloud数据库检查授权,并包括大量错误检查

func isAuthorized4Cloud() {
    appDelegate = UIApplication.shared.delegate as! AppDelegate
    container = CKContainer(identifier: "iCloud.blah.com")
    publicDB = container.publicCloudDatabase
    privateDB = container.privateCloudDatabase
    var userID: CKRecordID!
    container.fetchUserRecordID( completionHandler: { recordID, error in
        guard error == nil else {
            if let ckerror = error as? CKError {
                if ckerror.code == CKError.requestRateLimited {
                    let retryInterval = ckerror.userInfo[CKErrorRetryAfterKey] as? TimeInterval
                    DispatchQueue.main.async {
                        Timer.scheduledTimer(timeInterval: retryInterval!, target: self, selector: #selector(self.files_searchSet), userInfo: nil, repeats: false)
                    }
                } else if ckerror.code == CKError.zoneBusy {
                    let retryInterval = ckerror.userInfo[CKErrorRetryAfterKey] as? TimeInterval
                    DispatchQueue.main.async {
                        Timer.scheduledTimer(timeInterval: retryInterval!, target: self, selector: #selector(self.files_searchSet), userInfo: nil, repeats: false)
                    }
                } else if ckerror.code == CKError.limitExceeded {
                    let retryInterval = ckerror.userInfo[CKErrorRetryAfterKey] as? TimeInterval
                    DispatchQueue.main.async {
                        Timer.scheduledTimer(timeInterval: retryInterval!, target: self, selector: #selector(self.files_searchSet), userInfo: nil, repeats: false)
                    }
                } else if ckerror.code == CKError.notAuthenticated {
                    NotificationCenter.default.post(name: Notification.Name("noCloud"), object: nil, userInfo: nil)
                } else if ckerror.code == CKError.networkFailure {
                    NotificationCenter.default.post(name: Notification.Name("networkFailure"), object: nil, userInfo: nil)
                } else if ckerror.code == CKError.networkUnavailable {
                    NotificationCenter.default.post(name: Notification.Name("noWiFi"), object: nil, userInfo: nil)
                } else if ckerror.code == CKError.quotaExceeded {
                    NotificationCenter.default.post(name: Notification.Name("quotaExceeded"), object: nil, userInfo: nil)
                } else if ckerror.code == CKError.partialFailure {
                    NotificationCenter.default.post(name: Notification.Name("partialFailure"), object: nil, userInfo: nil)
                } else if (ckerror.code == CKError.internalError || ckerror.code == CKError.serviceUnavailable) {
                    NotificationCenter.default.post(name: Notification.Name("serviceUnavailable"), object: nil, userInfo: nil)
                }
            } // end of guard statement
            return
        }

        if error == nil {
            userID = recordID
            NotificationCenter.default.post(name: Notification.Name("cloudConnected"), object: nil, userInfo: nil)
        }
    })
}
您可能还想在cloudkit仪表板中查看数据库本身的权限,该仪表板将控制应用程序是否可以写入给定数据库