Я следил за CS193P и пытался воспроизвести скринкасты. В одном скринкасте есть пример получения twitter API и показа его как tableView. Но когда я попробовал, accountWithAccountType возвращает пустой массив. В результате это приводит к условию else
и показывает меня как Couldn't discover Twitter account type
. Мой код выглядит следующим образом
let accountStore = ACAccountStore()
let twitterAccountType = accountStore.accountTypeWithAccountTypeIdentifier(ACAccountTypeIdentifierTwitter)
accountStore.requestAccessToAccountsWithType(twitterAccountType, options: nil) { (granted, _) in
if granted {
// test is empty array
let test = accountStore.accountsWithAccountType(twitterAccountType)
println(test)
if let account = accountStore.accountsWithAccountType(twitterAccountType)?.last as? ACAccount {
twitterAccount = account
self.performTwitterRequest(request, handler: handler)
} else {
let error = "Couldn't discover Twitter account type."
self.log(error)
handler(error)
}
} else {
let error = "Access to Twitter was not granted."
self.log(error)
handler(error)
}
}
Когда я попытался напечатать twitterAccountType
, он показал Twitter (com.apple.twitter)
. Кстати, я тоже скачал по этой ссылке рабочую версию и попробовал. Он по-прежнему показывает ту же ошибку.