accountWithAccountType возвращает пустой массив

Я следил за 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). Кстати, я тоже скачал по этой ссылке рабочую версию и попробовал. Он по-прежнему показывает ту же ошибку.


person Naing Lin Aung    schedule 11.03.2015    source источник


Ответы (1)


Похоже, у вас нет учетной записи Twitter в настройках.

Перейдите в «Настройки» > «Твиттер» > «Войти со своим идентификатором в твиттере».

а затем повторите попытку.

Я тестировал на устройстве и симуляторе. Работает найти после добавления учетной записи Twitter.

person saturngod    schedule 11.03.2015
comment
Я не вижу твиттера в настройках. Где я могу найти его? - person Avinash Patil; 05.10.2017