ACAccountStore accountsWithAccountType返回空列表,但授予访问请求

时间:2015-04-18 18:57:32

标签: ios swift acaccountstore

我有以下一段Swift代码连接到我的iOS模拟器中的Twitter帐户。

我对requestAccessToAccountsWithType的调用已被授予,但ACAccountStore.accountsWithAccountType会返回一个空列表。

我错过了什么?

let accountStore = ACAccountStore()
let twitterAccountType = accountStore.accountTypeWithAccountTypeIdentifier(ACAccountTypeIdentifierTwitter)

accountStore.requestAccessToAccountsWithType(twitterAccountType, options: nil) { (granted, error) in
    if granted {
        print("requestAccessToAccountsWithType for \(twitterAccountType) is granted\n")
        let accounts = accountStore.accountsWithAccountType(twitterAccountType)
        print("accountsWithAccountType returns \(accounts.count) ")
    } else {
        let error = "Access to Twitter was not granted."
        self.log(error)
        handler(error)
    }
}
  

Twitter(com.apple.twitter)的requestAccessToAccountsWithType被授予   accountsWithAccountType返回0

1 个答案:

答案 0 :(得分:5)

授予访问权限是一回事,您还需要在设备/模拟器上配置Twitter帐户。检查您是否设置了任何帐户。