I'm running Xcode 12.4, testing on iOS 13 and 14.
How can a user be logged in/iCloud Available, but still Not Authenticated?
When I fetch a record, the CKErrorCode
is NotAuthenticated
and it prints Couldn't get an authentication token
let predicate = NSPredicate(format: "id == %@", id)
let query = CKQuery(recordType: RecordType.Media, predicate: predicate)
CKContainer.default().publicCloudDatabase.perform(query, inZoneWith: nil) { (ckRecords, error) in
if let err = error {
let code = err._code
// error code is 9 - case NotAuthenticated /* Not authenticated (writing without being logged in, no user record) */
return
}
// ...
}
But when I check to see if the user is logged in, I use the code below, and in both situations it prints iCloud Available
1-
if FileManager.default.ubiquityIdentityToken != nil {
print("iCloud Available")
} else {
print("iCloud Unavailable")
}
2-
CKContainer.default().accountStatus { (accountStatus, error) in
switch accountStatus {
case .available:
print("iCloud Available")
case .noAccount:
print("No iCloud account")
case .restricted:
print("iCloud restricted")
case .couldNotDetermine:
print("Unable to determine iCloud status")
@unknown default:
print("Unable to determine iCloud status")
}
}
FYI, this seems to happen in this order.
1- I'm home on wiFi, logged into iCloud, everything works fine.
2- I leave my house, switch to a hot spot, I'm still logged into iCloud and everything works fine
3- I come back into my house, switch back to wiFi, of course I'm still logged in, then the above issue occurs. It's as if it wants me to log in again even though I'm already logged in and it says iCloud Available
.
This issue is happening on both the real device and the simulator.
UPDATE
I just found this post, it seems lots of devs are having this same problem