如何在Cloudkit上存储数据

时间:2019-01-05 06:16:52

标签: ios swift cloudkit

我已成功将应用程序的数据存储在cloudkit上,但是当我尝试存储第二个应用程序时,出现了这样的错误:

  

“ CKError 0x600001 d719b0:“权限失败”(10/2007);服务器   消息=“不允许创建操作”; UUID =   D41B3F33-102B-411D-9CE7-183CD04569DA;容器编号=   iCloud.com.codery.ntd>“

这是我的代码:

let now = Date()
    let timeInterval:TimeInterval = now.timeIntervalSince1970
    let timeStamp = Int(timeInterval)
    let publicDB = CKContainer.default().publicCloudDatabase
    let bookID = CKRecord.ID(recordName: "\(timeStamp)")
    let book = CKRecord(recordType: "Book", recordID: bookID)
    book.setValue("Swift", forKey: "name")

    publicDB.save(book) { savedRecord , error in

        if error == nil {

            print("success")

        }else {


            print(error)

        }

    }

1 个答案:

答案 0 :(得分:0)

这可能就是答案。

Possible to set default CloudKit container not based on application name?

let container = CKContainer(identifier: "iCloud.com.kukodajanos.Dating")
let publicDB = container.publicCloudDatabase
let privateDB = container.privateCloudDatabase

两个应用程序在此处显示的标识符是否相同。