【问题标题】:cloudKit: CKSubscription error "This request requires an authenticated account""cloudKit:CKSubscription 错误“此请求需要经过身份验证的帐户””
【发布时间】:2014-12-05 11:41:29
【问题描述】:

我正在测试我的应用,但没有经过身份验证的 iCloud 帐户,但在订阅设备接收通知时出现此错误:

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

这没关系,但我的问题是如何在尝试运行 CKSubscription 代码之前检查设备是否登录到 iCloud?

非常感谢您的帮助。

【问题讨论】:

标签: ios objective-c xcode cloudkit


【解决方案1】:

我最终在这里在 google 上搜索“cloudkit This request requires an authenticated account”。对我来说,问题是我没有在模拟器中登录 iCloud。我有种假设我会自动在我的开发 Apple ID 下运行......

【讨论】:

  • 每个人都有超级复杂的答案,这是我的问题。非常感谢!
【解决方案2】:

您可以在容器上使用 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)")
    })

【讨论】:

    【解决方案3】:

    这是 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);
    
            }
        } ];
    

    【讨论】:

    • 不要将accountStatus 与硬编码的整数进行比较。与枚举值进行比较:if (accountStatus == CKAccountStatusNoAccount)`。这更具可读性并且更不容易出错。
    【解决方案4】:

    在 swift 2 中,您将状态与

    进行比较
    case CouldNotDetermine
    case Available
    case Restricted
    case NoAccount
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多