iOS返回说手机上没有推特账号,尽管有账号 [英] iOS returns that there are no twitter accounts on phone, eventhough there is one

查看:261
本文介绍了iOS返回说手机上没有推特账号,尽管有账号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我检查是否有使用此代码的Twitter帐户:

I check if there is used twitter account with this code:

ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

NSArray *arrayOfAccounts = [accountStore accountsWithAccountType:accountType];

如果我在iOS 6模拟器上使用 twitter account, arrayOfAccounts.count 是1,但在iPhone 4 iOS6上, arrayOfAccounts.count 为0。

If i run it on iOS 6 simulator with twitter account, arrayOfAccounts.count is 1, but on iPhone 4 iOS6, arrayOfAccounts.count is 0.

我做错了什么?

推荐答案

我也遇到了同样的问题。使用此代码。

I also got same problem. Use this code.

原因是它没有获得Twitter帐户访问设置的权限,因此我们需要先检查一下。

Reason for this is that it does not get permissions from settings for Twitter account access, so we need to check that first.

if ([TWRequest class])
            {
                ACAccountStore *account = [[ACAccountStore alloc] init];
                ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:
                                              ACAccountTypeIdentifierTwitter];

                [account requestAccessToAccountsWithType:accountType options:nil
                                              completion:^(BOOL granted, NSError *error)
                 {
                     if (granted == YES)
                     {
                         // Get account and communicate with Twitter API
                         NSArray *arrayOfAccounts = [account
                                                     accountsWithAccountType:accountType];

                         if ([arrayOfAccounts count] > 0)
                         {
                             ACAccount *twitterAccount = [arrayOfAccounts lastObject];
                         }
                  }
                     else
                     {
                         NSLog(@"No Twitter Access Error");
                         return;
                     }
                 }];
            }



            if ([TWRequest class])
            {
                ACAccountStore *as = [[ACAccountStore alloc] init];
                ACAccountType *accountType = [as accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
                NSArray *twitterAccounts = [as accountsWithAccountType:accountType];
                if (!twitterAccounts.count)
                {
                    NSLog(@"No Twitter Account configured");

                    return;
                }
            }
}

这篇关于iOS返回说手机上没有推特账号,尽管有账号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆