Search code examples
iosswiftcloudkit

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


There is a real lack of documentation and information in general out there regarding the public container of CloudKit. I'm having an issue where data cannot be sent while a device is on its cellular network, but works perfectly fine when connected to 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")
    }
}

I keep getting an error that says:

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

when the cellular connection is definitely not the issue on my device.


Solution

  • I wonder if this might be a setting on the device. Have you checked that iCloud Drive is allowed to use cellular data?

    On your iPhone/iPad, go to Settings > Cellular > iCloud Drive (way down at the bottom; make sure it's turned on).