只能通过 wifi 连接到 CloudKit 的 public 容器,但不能通过蜂窝网络连接

Can only connect to the public container of CloudKit through wifi, but not cellular

关于 CloudKit 的 public 容器,总体上确实缺乏文档和信息。我遇到一个问题,当设备在其蜂窝网络上时无法发送数据,但在连接到 Wifi 时工作正常。

let publicCloudDatabase = CKContainer.default().publicCloudDatabase
let operation = CKModifyRecordsOperation(recordsToSave: [exampleRecord], recordIDsToDelete: nil)
let operationConfiguration = CKOperation.Configuration()

operationConfiguration.allowsCellularAccess = true
operationConfiguration.qualityOfService = .userInitiated
operation.configuration = operationConfiguration

operation.perRecordProgressBlock = {(record, progress) in
    print(progress)
}

operation.perRecordCompletionBlock = {(record, error) in
    print("Upload complete")
}

publicCloudDatabase.add(operation)
publicCloudDatabase.save(exampleRecord) { [unowned self] record, error in
    if let error = error {
        print("public cloud database error: \(error)")
    } else {
        print("Sucessfully uploaded to Public Cloud DB")
    }
}

我不断收到一条错误消息:

CKError 0x281ff9ec0: "Network Unavailable" (3/NSURLErrorDomain:-1009); "The Internet connection appears to be offline."

当手机连接绝对不是我设备上的问题时。

我想知道这是否是设备上的设置。您是否检查过 iCloud Drive 是否允许使用蜂窝数据?

在您的 iPhone/iPad 上,转到 Settings > Cellular > iCloud Drive(一直在底部;确保它已打开)。