Dix*_*ine 1 iphone twitter objective-c ios
我检查是否有使用此代码的Twitter帐户:
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
NSArray *arrayOfAccounts = [accountStore accountsWithAccountType:accountType];
Run Code Online (Sandbox Code Playgroud)
如果我在带有twitter帐户的iOS 6模拟器上运行它arrayOfAccounts.count是1,但在iPhone 4 iOS6上,arrayOfAccounts.count则为0.
我究竟做错了什么?
我也有同样的问题.使用此代码.
原因是它没有获得Twitter帐户访问设置的权限,因此我们需要先检查它.
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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2978 次 |
| 最近记录: |