iOS twitter检查帐户是否可用

时间:2013-08-28 11:13:30

标签: ios twitter acaccountstore

我正在开发一个应用程序(iOS5 +),我在Twitter上发布。我想检查系统是否配置了Twitter帐户,以便他们可以通过Twitter登录,如果帐户可用,否则他们将被呈现webview以登录(使用unofficial-twitter-sdk)或者他们将被发送到设置将Twitter帐户添加到系统(但我不喜欢这种方式,因为你无法将用户带回应用程序)。

这种方法的唯一问题是在模拟器上我可以使用

检查有多少帐户
ACAccountType *twitterAccountType = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Get the list of Twitter accounts and checks
NSArray *accountsArray = [_accountStore accountsWithAccountType:twitterAccountType];

虽然相同的代码在真实设备上不起作用,但总是报告该数组为空(因为它只返回已经允许该应用程序使用Twitter的权限的帐户)。

第二种方法是使用-ACAccountStore requestAccessToAccountsWithType:withCompletionHandler:方法的完成处理程序,特别是

// We can user the twitter iOS accounts, but we use a custom view to post the content
[_accountStore requestAccessToAccountsWithType:twitterAccountType withCompletionHandler:^(BOOL granted, NSError *error) {
if (granted)
{
// POST
}
else
{
// error?
}

但在第二种情况下,在以下任何一种情况下,错误总是为零: 1.用户未授予使用系统帐户的权限 2.没有可用的帐户

所以基本上我不能以任何方式区分这两种情况,因此我不知道我是否应该向用户提供登录视图(第二种情况)或者因为他们不想登录而失败。

有什么见解?有解决方法吗?

0 个答案:

没有答案