CKContainer accountStatusWithCompletionHandler returns wrong value

主宰稳场 提交于 2020-01-14 13:49:12

问题


accountStatusWithCompletionHandler method returns .NoAccount value. Any idea why returned value is not .Available? I am logged in to iCloud, and connecting to internet.

Doc says .NoAccount means:

The user’s iCloud account is not available because no account information has been provided for this device.

I do not receive any error. The reason may be that app is not using private database? Doc says:

Call this method before accessing the private database to determine whether that database is available.


回答1:


Figured out, iCloud Drive was turned off for the app.




回答2:


This code sample show status with iCloud. Probably request permission or promo user to login on .NoAccount case. I am thinking this is a case when you are not connected to the iCloude.

let container = CKContainer.defaultContainer()
    container.accountStatusWithCompletionHandler({status, error in
        switch status {
            case .Available, .Restricted:
            container.requestApplicationPermission(CKApplicationPermissions.PermissionUserDiscoverability,
                completionHandler: { applicationPermissionStatus, error in
                // handle applicationPermissionStatus for statuses like CKApplicationPermissionStatus.Granted, .Denied, .CouldNotComplete, .InitialState
            })
            case .CouldNotDetermine, .NoAccount:
                // Ask user to login to iCloud
        }
    })


来源:https://stackoverflow.com/questions/34091839/ckcontainer-accountstatuswithcompletionhandler-returns-wrong-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!