Please see my updated question below:
I am working on my first app with CloudKit. I'm trying to test whether a user is connected to iCloud, before looking for transactions.
This is my code (showing various tests):
func isICloudContainerAvailable()->Bool {
CKContainer.default().accountStatus { (accountStat, error) in
if (accountStat == .available) {
print("iCloud is available")
}
else {
print("iCloud is not available")
}
}
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")
}
}
if FileManager.default.ubiquityIdentityToken != nil {
//print("User logged in")
return true
}
else {
//print("User is not logged in")
return false
}
}
This works ok for my own account -- I can work as expected. However, for new users, (ie Apple Review team and my own test users), I get
iCloud Unavailable, and No iCloud Account
I'm sure that there is an open iCloud account as the new user's iCloud mail is working.
UPDATE
I've had a test user log out and log in again. The first time she starts the app, she gets the noCloud messages. If she restarts the app, it works. I could use some ideas on places to look.. I have confirmed this behavior using my own computer with a new test account.
According to the documentation,
The private database is available only when the value in the ubiquityIdentityToken property is not nil.
There are times when iCloud may not be available to your app, such as when the user disables the Documents & Data feature or signs out of iCloud.
Documents and Data is now apparently what is called iCloud Drive in Settings.
So I would ask the users in question if their iCloud Drive setting is enabled and if turning it on makes any difference.