3

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.

Tom Harrington
  • 69,312
  • 10
  • 146
  • 170
user2924482
  • 8,380
  • 23
  • 89
  • 173
  • Possible duplicate of [Saving CloudKit Record "Not Authenticated" (9/1002)" "This request requires an authenticated account""](http://stackoverflow.com/questions/26253415/saving-cloudkit-record-not-authenticated-9-1002-this-request-requires-an-a) – brainray Dec 04 '16 at 23:06
  • [See this asnwer](http://stackoverflow.com/questions/27315155/cloudkit-cksubscription-error-this-request-requires-an-authenticated-account/42473794#42473794), sometimes it can be stupid error. – Nosov Pavel Feb 26 '17 at 20:25

4 Answers4

11

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...

boxed
  • 3,895
  • 2
  • 24
  • 26
0

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)")
    })
Edwin Vermeer
  • 13,017
  • 2
  • 34
  • 58
0

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);

        }
    } ];
user2924482
  • 8,380
  • 23
  • 89
  • 173
  • 1
    Do not compare `accountStatus` against hardcoded integers. Compare against the enum values: `if (accountStatus == CKAccountStatusNoAccount`)`. This is much more readable and far less error prone. – rmaddy Sep 14 '15 at 15:30
0

in swift 2 you compare status to

case CouldNotDetermine
case Available
case Restricted
case NoAccount
Adam Smaka
  • 5,977
  • 3
  • 50
  • 55