Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios cloudKit:CKSubscription错误“;此请求需要经过身份验证的帐户&引用;_Ios_Objective C_Xcode_Cloudkit - Fatal编程技术网

Ios cloudKit:CKSubscription错误“;此请求需要经过身份验证的帐户&引用;

Ios cloudKit:CKSubscription错误“;此请求需要经过身份验证的帐户&引用;,ios,objective-c,xcode,cloudkit,Ios,Objective C,Xcode,Cloudkit,我正在测试没有经过身份验证的iCloud帐户的应用程序,但在订阅设备以获取通知时出现以下错误: subscription error<CKError 0x1700581e0: "Not Authenticated" (9/1002); "This request requires an authenticated account"; Retry after 3.0 seconds> 订阅错误 这没问题,但我的问题是,在尝试运行CKSubscription代码之前,如何检查设备是

我正在测试没有经过身份验证的iCloud帐户的应用程序,但在订阅设备以获取通知时出现以下错误:

subscription  error<CKError 0x1700581e0: "Not Authenticated" (9/1002); "This request requires an authenticated account"; Retry after 3.0 seconds>
订阅错误
这没问题,但我的问题是,在尝试运行CKSubscription代码之前,如何检查设备是否登录到iCloud


非常感谢您的帮助。

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

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

        }
    } ];

最后,我在google上搜索了“cloudkit此请求需要经过身份验证的帐户”。我的问题是,我没有在模拟器内登录到iCloud。我有点假设我会在我的开发Apple ID下自动运行…

在swift 2中,您可以将状态与之进行比较

case CouldNotDetermine
case Available
case Restricted
case NoAccount

每个人都有非常复杂的答案,这就是我的问题。非常感谢!不要将
accountStatus
与硬编码整数进行比较。与枚举值比较:
if(accountStatus==CKAccountStatusNoAccount
)`。这更具可读性,更不容易出错。可能会重复,有时可能是愚蠢的错误。