Reputation: 9120
I'm testing my app with no authenticated iCloud accounts but I'm getting this error when to subscribe the device for notifications:
subscription error<CKError 0x1700581e0: "Not Authenticated" (9/1002); "This request requires an authenticated account"; Retry after 3.0 seconds>
This is Ok but my question is how can check if the device is login to iCloud before try to run the CKSubscription code?
I'll really appreciate your help.
Upvotes: 3
Views: 2736
Reputation: 6393
in swift 2 you compare status to
case CouldNotDetermine
case Available
case Restricted
case NoAccount
Upvotes: 0
Reputation: 4417
I ended up here searching for "cloudkit This request requires an authenticated account" on google. The problem for me was that I wasn't signed in to iCloud inside the simulator. I had kind of assumed I would be running under my development Apple ID automatically...
Upvotes: 12
Reputation: 9120
This is the Objective-C version:
CKContainer *container = [CKContainer defaultContainer];
[container accountStatusWithCompletionHandler:^(CKAccountStatus accountStatus, NSError *error)
{
if (((accountStatus == 3) || (accountStatus == 2)) && (!error))
{
NSLog(@" no error but status %ld",accountStatus);
// typedef NS_ENUM(NSInteger, CKAccountStatus) {
// /* An error occurred when getting the account status, consult the corresponding NSError */
// CKAccountStatusCouldNotDetermine = 0,
// /* The iCloud account credentials are available for this application */
// CKAccountStatusAvailable = 1,
// /* Parental Controls / Device Management has denied access to iCloud account credentials */
// CKAccountStatusRestricted = 2,
// /* No iCloud account is logged in on this device */
// CKAccountStatusNoAccount = 3,
//
// }
}
if (error)
{
NSLog(@" accountStatus error %@",error);
}
} ];
Upvotes: 0
Reputation: 13127
You can use the accountStatusWithCompletionHandler method on the container. If you want to use subscriptions, then it should return a status with a .hashValue of 1
container = CKContainer.defaultContainer()
container.accountStatusWithCompletionHandler({status, error in
if (error != nil) { NSLog("Error = \(error.description)")}
NSLog("Account status = \(status.hashValue) (0=CouldNotDetermine/1=Available/2=Restricted/3=NoAccount)")
})
Upvotes: 0