所以我创建了这个函数来将资源上传到CloudKit。
func uploadAsset(recordType: String, fileURL: URL, reference: String) {
let record = CKRecord(recordType: recordType)
record["file"] = CKAsset(fileURL: fileURL)
let modifyRecordsOperation = CKModifyRecordsOperation(
recordsToSave: [record],
recordIDsToDelete: nil)
modifyRecordsOperation.timeoutIntervalForRequest = 10
modifyRecordsOperation.timeoutIntervalForResource = 10
modifyRecordsOperation.modifyRecordsCompletionBlock =
{ records, recordIDs, error in
print("DEBUG: smodifyRecordsCompletionBlock reached")
if let err = error {
print("DEBUG: uhoh error " + err.localizedDescription)
} else {
print("DEBUG: success")
}
}
modifyRecordsOperation.perRecordProgressBlock = {
self.updateProgressView(progress: Float($1))
print( "DEBUG: progress = ", $1 )
}
modifyRecordsOperation.completionBlock = {
self.hideProgressView(hide: true)
print("DEBUG: Ding, completion block hit!")
}
if (!Reachability.isInternetAvailable()) {
print("DEBUG: uhoh error no internet connection")
} else {
CKContainer(identifier: "iCloud.com.example-container").publicCloudDatabase.add(modifyRecordsOperation)
print("DEBUG: should have started cloud upload")
}
}
现在这对我自己来说非常好,但对我的客户来说却失败了。但错误信息并不是最有见地的,它说:
DEBUG: should have started cloud upload
file saved
DEBUG: smodifyRecordsCompletionBlock reached
我已经仔细检查过,我的客户在他的测试设备上登录了iCloud。我在这里缺少什么?