如何将资产保存到CloudKit sharedCloudDatabase?

时间:2017-02-16 10:50:57

标签: ios swift cloudkit

我收到以下错误:

  

CKError 0x6180000575b0发生错误:“参数无效”(12/2006); server message =“由于userId无效,无法将userId转换为dsId。请检查userId的格式。”; uuid = E843A411-D192-4435-BAC1-F52EDCA87990; container ID =“iCloud.com.example.myApp”

我的代码如下:

func uploadAsset(recordType: String, fileURL: URL) {
    let documentsDirectoryURL =  FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!

    let asset = CKAsset(fileURL: fileURL)

    let recordZoneID = CKRecordZoneID(zoneName: "Notes", ownerName: "_abcdeg")
    let record = CKRecord(recordType: recordType, zoneID: recordZoneID)
    record.setObject(asset, forKey: "file")

    CKContainer.default().sharedCloudDatabase.save(record) { savedRecord, error in
        if let saveError = error {
            print("An error occurred in \(saveError)") 
        } else {
            print(savedRecord)
    }
}

任何帮助表示赞赏。提前谢谢。

1 个答案:

答案 0 :(得分:0)

我是一个完整的快速ios新手并且遇到了同样的问题。这是因为在区域ID中设置了错误的ownerName。请改用此方法:

let recordZoneID = CKRecordZone(zoneName: "Notes").zoneID

然后所有者将被设置为当前用户。