在我的应用程序中,在发布模式下保存或更新CKRecords到iCloud(使用ad-hoc,app store配置文件构建)无效。
在功能中创建默认容器,并找到下面附带的屏幕截图。
let container = CKContainer.default
var privateDatabase: CKDatabase?
var currentRecord: CKRecord?
var photoURL: URL?
var recordZone: CKRecordZone?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
privateDatabase = container().privateCloudDatabase
recordZone = CKRecordZone(zoneName: "HouseZone")
privateDatabase?.save(recordZone!,
completionHandler: {(recordzone, error) in
if (error != nil) {
self.notifyUser("Record Zone Error",
message: "Failed to create custom record zone.")
} else {
print("Saved record zone")
}
})
}
@IBAction func saveAction(_ sender: Any) {
if let img = selImageView.image{
photoURL = self.saveImageToFile(img)
}
let asset = CKAsset(fileURL: photoURL!)
let myRecord = CKRecord(recordType: "Houses",
zoneID: (recordZone?.zoneID)!)
myRecord.setObject(addressTextField.text as CKRecordValue?,
forKey: "address")
myRecord.setObject(descriptionTextView.text as CKRecordValue?,
forKey: "comment")
myRecord.setObject(asset, forKey: "photo")
let modifyRecordsOperation = CKModifyRecordsOperation(
recordsToSave: [myRecord],
recordIDsToDelete: nil)
if #available(iOS 10.0, *) {
modifyRecordsOperation.timeoutIntervalForRequest = 10
} else {
// Fallback on earlier versions
// modifyRecordsOperation.timeoutIntervalForRequest = 10
}
modifyRecordsOperation.modifyRecordsCompletionBlock =
{ records, recordIDs, error in
if let err = error {
self.notifyUser("Save Error", message:
err.localizedDescription)
} else {
DispatchQueue.main.async {
self.notifyUser("Success",
message: "Record saved successfully")
}
self.currentRecord = myRecord
}
}
privateDatabase?.add(modifyRecordsOperation)
}
以上代码在调试模式下工作。当我使用Ad-hoc配置文件生成构建时无效。
将应用程序提交到appstore并尝试过,仍然无法正常工作。 请建议,
答案 0 :(得分:0)
好的,所以我现在重复了两次错误 - 对我来说,这是因为我向CKRecord添加了新字段,但没有将Development CloudKit数据库部署到Production。
原因是当CKRecord有新字段时,开发数据库会自动更新,但在您进行显式部署之前,它不会进入生产阶段。因此,在Prod环境中,由于未知字段,对数据库的写入将被拒绝。
要修复它,请转到CloudKit仪表板,确保它在开发环境中,然后单击部署,您应该会看到要部署的新字段。部署后,它应该立即工作。