3

我有以下 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

4

1 回答 1

6

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

于 2015-04-19T22:25:40.493 回答