1

正在开发我在 Twitter 上发布的应用程序 (iOS5+)。我想检查系统是否配置了 Twitter 帐户,如果帐户可用,他们可以通过 Twitter 登录,否则他们将被显示一个 web 视图以登录(使用 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. 没有可用的帐户

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

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

4

0 回答 0