I have an app that's been rejected because I test whether the user has access to their CloudKit containers.
If they are not connected, I issue a warning, and tell them to quit the app.
I can't be the only one to experience this.. Any one have a workaround?
Thanks..
For information, the code I'm using to test was sent to me from an Apple TSI engineer. sigh..
Here it is:
func isICloudContainerAvailable()->Bool {
print(#function)
CKContainer.default().accountStatus { (accountStatus, error) in
if accountStatus == .available {
print(#function, "accountStatus 1: ", accountStatus)
return
} else {
print(#function, "accountStatus 2: ", accountStatus)
}
DispatchQueue.global().asyncAfter(deadline: .now() + 0.3) {
guard error != nil, accountStatus != CKAccountStatus.available else {return}
print( #function, "accountStatus 3: ", accountStatus)
print("iCloud account is not available! Be sure you have signed in iCloud on this device!")
}
}
if FileManager.default.ubiquityIdentityToken != nil {
print("User logged in")
return true
}
else {
print("User is not logged in")
return false
}
}
And the function is used here:
if !isICloudContainerAvailable() {
let alertController = UIAlertController(title: "Uh-oh", message: "You must be signed into iCloud \nto use this app.\nPlease quit, log in to iCloud using the 'Settings' app\nand try again", preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alertController.addAction(defaultAction)
self.present(alertController, animated: true, completion: nil)
})