ios - ACAccountStore accountsWithAccountType 返回空列表但访问请求被授予

标签 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)
    }
}

requestAccessToAccountsWithType for Twitter (com.apple.twitter) is granted accountsWithAccountType returns 0

最佳答案

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

关于ios - ACAccountStore accountsWithAccountType 返回空列表但访问请求被授予,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29721496/

相关文章:

iOS Facebook 登录教程

ios - 如何检测用户是否从 native 操作系统登录 Facebook

ios - 切换 View Controller 后 NSTimer 触发两次

ios - KVO和NSNotificationCenter的正确用法和区别是什么?

iphone - 在窗口级别获取键盘框架

ios - 如何使用手势 swift iOS 转换到 View Controller

iphone - 获取我的应用程序是否被授权使用 facebook [iOS 6, FB SDK 3.2]

从线快速查看动画

swift - 随着屏幕尺寸的增加,触摸屏在屏幕上形成的路径正在缩小

twrequest - requestAccessToAccountsWithType 在 ios6.1 中已被弃用,我应该使用什么来代替?