2014-12-05 68 views
2

我測試我沒有驗證的的iCloud帳戶應用程序,但我得到這個錯誤時,以認購該設備的通知:cloudKit:CKSubscription錯誤「這一請求需要經過身份驗證的帳戶」,」

subscription error<CKError 0x1700581e0: "Not Authenticated" (9/1002); "This request requires an authenticated account"; Retry after 3.0 seconds> 

這是好,但我的問題是如何檢查設備是否登錄到iCloud嘗試之前運行CKSubscription代碼?

我會很感激你的幫助。

+0

的[保存CloudKit記錄「未通過身份驗證」可能的複製(1002分之9 )「」此請求需要經過身份驗證的帳戶「」](http://stackoverflow.com/questions/26253415/saving-cloudkit-record-not-authenticated-9-1002-this-request-requires-an-a) – brainray 2016-12-04 23:06:18

+0

[看到這個asnwer](http://stackoverflow.com/questions/27315155/cloudkit-cksubscription-error-this-request-requires-an-authenticated-account/42473794#42473794),有時它可能是愚蠢的錯誤。 – 2017-02-26 20:25:19

回答

0

您可以使用accountStatusWithCompletionHandler方法在容器上。如果你想使用訂閱,那麼它應該返回狀態與.hashValue 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)") 
    }) 
0

這是Objective-C的版本:

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

     } 
    } ]; 
+1

不要將'accountStatus'與硬編碼整數進行比較。與枚舉值比較:'if(accountStatus == CKAccountStatusNoAccount')'。這是更可讀,更不容易出錯。 – rmaddy 2015-09-14 15:30:59

7

我在這裏結束了尋找「cloudkit此請求需要經過身份驗證帳戶「在谷歌。我面臨的問題是我沒有登錄到模擬器中的iCloud。我曾經那種認爲我會在我的開發自動的Apple ID運行...

+0

每個人都有超複雜的答案,這是我的問題。非常感謝! – SomeGuy 2015-05-12 23:45:41

0
斯威夫特2

你比較狀態

case CouldNotDetermine 
case Available 
case Restricted 
case NoAccount 
相關問題