twitter帐户列表代码在iOS 6中有效,而在iOS 7中无效?

twitter帐户列表代码在iOS 6中有效,而在iOS 7中无效?,ios,twitter,ios6,ios7,Ios,Twitter,Ios6,Ios7,为什么下面的代码在ios6中运行良好,而在ios7中运行不正常?我是否错过了ios 7的某些功能 ACAccountStore *account_Store = [[ACAccountStore alloc] init]; ACAccountType *account_Type = [account_Store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; arrayOfAccounts =

为什么下面的代码
在ios6中运行良好,而在ios7中运行不正常?我是否错过了ios 7的某些功能

ACAccountStore *account_Store = [[ACAccountStore alloc] init];
ACAccountType *account_Type = [account_Store     accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
 arrayOfAccounts = [[NSMutableArray alloc]initWithArray:[account_Store accountsWithAccountType:account_Type]];


NSLog(@"arrayOfAccounts %@",arrayOfAccounts); 


if ([arrayOfAccounts count] > 0)
{
    ACAccount *acct1;
    array = [[NSMutableArray alloc]init];

    for (int i = 0 ; i < [arrayOfAccounts count]; i++ )
    {
        acct1 = [[ACAccount alloc]init];
        acct1 = [arrayOfAccounts objectAtIndex:i];
        [array setObject:[NSString stringWithFormat:@"%@",acct1.username] atIndexedSubscript:i];
        // NSString *username = acct1.username;
        // NSLog(@"user at index %d : username %@",i,username);

    }
}
ACAccountStore*account\u Store=[[ACAccountStore alloc]init];
ACAccountType*account\u Type=[账户存储accountTypeWithAccountTypeIdentifier:acaccounttypeidentifierwitter];
arrayOfAccounts=[[NSMutableArray alloc]initWithArray:[account\u Store accountsWithAccountType:account\u Type]];
NSLog(@“arrayOfAccounts%@”,arrayOfAccounts);
如果([arrayOfAccounts]>0)
{
ACAccount*acct1;
array=[[NSMutableArray alloc]init];
对于(int i=0;i<[arrayOfAccounts];i++)
{
acct1=[[ACAccount alloc]init];
acct1=[arrayOfAccounts对象索引:i];
[array setObject:[NSString stringWithFormat:@“%@”,acct1.username]a索引下标:i];
//NSString*username=acct1.username;
//NSLog(@“索引%d处的用户:用户名%@”,i,用户名);
}
}
此语句
NSLog(@“arrayOfAccounts%@”,arrayOfAccounts)提供输出:

阵列传真计数()

尝试此操作(您需要请求访问帐户)

尝试此操作(您需要请求访问帐户)


我曾经这样做是为了获得一系列的帐户,它确实给了我在ios 6和ios 7上的支持。 如果有用,试试看。谢谢

在.h文件中导入这些框架

#import <Twitter/Twitter.h>
#import <Accounts/Accounts.h>
#导入
#进口
将此ARC兼容代码添加到.m文件中的任何按钮操作或您要在其上设置帐户数组--

/*
//ios 6和ios 7的工作代码
if(楼层(NSFoundationVersionNumber)0)
{
ACAccount*acct1;
array=[[NSMutableArray alloc]init];
对于(int i=0;i<[arrayOfAccounts];i++)
{
acct1=[[ACAccount alloc]init];
acct1=[arrayOfAccounts对象索引:i];
[array setObject:[NSString stringWithFormat:@“%@”,acct1.username]a索引下标:i];
//NSString*username=acct1.username;
//NSLog(@“索引%d处的用户:用户名%@”,i,用户名);
}
//NSLog(@“数组%@”,数组);
UIActionSheet*actionSheet=[[UIActionSheet alloc]initWithTitle:@“选择您的Twitter帐户”
代表:赛尔夫
取消按钮:无
破坏性按钮:无
其他按钮:无];
//快速枚举
对于(int i=0;i<[数组计数];i++)
{
[actionSheet addButtonWithTitle:[array objectAtIndex:i]];
}
[actionSheet AddButton,标题为@“取消”];
actionSheet.cancelButtonIndex=[数组计数];
[actionSheet showInView:self.view];
}
其他的
{
UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@“Twitter”消息:@“您没有Twitter帐户”委托:自我取消按钮:@“确定”其他按钮:无];
alert.tag=999;
[警报显示];
}
});
}
}];
}

我过去经常这样做来获取帐户数组,它确实为我在ios 6和ios 7上提供了支持。 如果有用,试试看。谢谢

在.h文件中导入这些框架

#import <Twitter/Twitter.h>
#import <Accounts/Accounts.h>
#导入
#进口
将此ARC兼容代码添加到.m文件中的任何按钮操作或您要在其上设置帐户数组--

/*
//ios 6和ios 7的工作代码
if(楼层(NSFoundationVersionNumber)0)
{
ACAccount*acct1;
array=[[NSMutableArray alloc]init];
对于(int i=0;i<[arrayOfAccounts];i++)
{
acct1=[[ACAccount alloc]init];
acct1=[arrayOfAccounts对象索引:i];
[array setObject:[NSString stringWithFormat:@“%@”,acct1.username]a索引下标:i];
//NSString*username=acct1.username;
//NSLog(@“索引%d处的用户:用户名%@”,i,用户名);
}
//NSLog(@“数组%@”,数组);
UIActionSheet*actionSheet=[[UIActionSheet alloc]initWithTitle:@“选择您的Twitter帐户”
代表:赛尔夫
取消按钮:无
破坏性按钮:无
其他按钮:无];
//快速枚举
对于(int i=0;i<[数组计数];i++)
{
[actionSheet addButtonWithTitle:[array objectAtIndex:i]];
}
[actionSheet AddButton,标题为@“取消”];
actionSheet.cancelButtonIndex=[数组计数];
[actionSheet showInView:self.view];
}
其他的
{
UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@“Twitter”消息:@“您没有Twitter帐户”委托:自我取消按钮:@“确定”其他按钮:无];
alert.tag=999;
[警报显示];
}
});
}
}];
}

这是在模拟器上还是在电话上?您是否在iOS 7模拟器上设置了Twitter帐户?是的,我已经在模拟器和设备上进行了测试,并且我也通过设置设置了Twitter帐户。这是在模拟器上还是在手机上?你在iOS 7模拟器上设置了Twitter帐户吗?是的,我在这两个模拟器上都进行了测试
  /*

// working code for ios 6 and ios 7

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1)
{
   // ios 6 working code
}
else 
{
  // ios 7 working code

}

 */

  ACAccountStore *account_Store = [[ACAccountStore alloc] init];
ACAccountType *account_Type = [account_Store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];


if (!account_Type)
{

    UIAlertView *alert1 = [[UIAlertView alloc]initWithTitle:@"Twitter" message:@"Permission not granted" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    alert1.tag = 888;
    [alert1 show];
    return;
}


if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1)
{
    [arrayOfAccounts removeAllObjects];
    [array removeAllObjects];
    arrayOfAccounts = [[NSMutableArray alloc]initWithArray:[account_Store accountsWithAccountType:account_Type]];
    NSLog(@"arrayOfAccounts %@",arrayOfAccounts);

    if ([arrayOfAccounts count] > 0)
    {
        ACAccount *acct1;
        array = [[NSMutableArray alloc]init];

        for (int i = 0 ; i < [arrayOfAccounts count]; i++ )
        {
            acct1 = [[ACAccount alloc]init];
            acct1 = [arrayOfAccounts objectAtIndex:i];
            [array setObject:[NSString stringWithFormat:@"%@",acct1.username] atIndexedSubscript:i];
            // NSString *username = acct1.username;
            // NSLog(@"user at index %d : username %@",i,username);

        }

        //  NSLog(@"array %@",array);

        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select your Twitter Account"
                                                                 delegate:self
                                                        cancelButtonTitle:nil
                                                   destructiveButtonTitle:nil
                                                        otherButtonTitles:nil];

        // ObjC Fast Enumeration
        for (int i = 0 ; i < [array count]; i++)
        {
            [actionSheet addButtonWithTitle:[array objectAtIndex:i]];
        }

        [actionSheet addButtonWithTitle:@"Cancel"];
        actionSheet.cancelButtonIndex = [array count];

        [actionSheet showInView:self.view];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Twitter" message:@"You have no twitter account" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        alert.tag = 999;

        [alert show];

    }



}
else // ios 7 working code
{


[account_Store requestAccessToAccountsWithType:account_Type options:nil completion:^(BOOL granted, NSError *error)
{
    if (granted)
    {
            dispatch_sync(dispatch_get_main_queue(), ^{

            arrayOfAccounts = [[NSMutableArray alloc]initWithArray:[account_Store accountsWithAccountType:account_Type]];
            NSLog(@"arrayOfAccounts %@",arrayOfAccounts);

            if ([arrayOfAccounts count] > 0)
            {
                ACAccount *acct1;
                array = [[NSMutableArray alloc]init];

                for (int i = 0 ; i < [arrayOfAccounts count]; i++ )
                {
                    acct1 = [[ACAccount alloc]init];
                    acct1 = [arrayOfAccounts objectAtIndex:i];
                    [array setObject:[NSString stringWithFormat:@"%@",acct1.username] atIndexedSubscript:i];
                    // NSString *username = acct1.username;
                    // NSLog(@"user at index %d : username %@",i,username);

                }

                //  NSLog(@"array %@",array);

                UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select your Twitter Account"
                                                                         delegate:self
                                                                cancelButtonTitle:nil
                                                           destructiveButtonTitle:nil
                                                                otherButtonTitles:nil];

                // ObjC Fast Enumeration
                for (int i = 0 ; i < [array count]; i++)
                {
                    [actionSheet addButtonWithTitle:[array objectAtIndex:i]];
                }

                [actionSheet addButtonWithTitle:@"Cancel"];
                actionSheet.cancelButtonIndex = [array count];

                [actionSheet showInView:self.view];

            }
            else
            {

                UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Twitter" message:@"You have no twitter account" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                alert.tag = 999;

                [alert show];

            }

            });

            }

}];
}