twitter.framework问题

时间:2012-11-05 09:34:32

标签: iphone objective-c twitter ios5.1

我正在尝试在iOS 5上使用twitter实现单点登录,它一切正常,除非在settings.app中没有帐户,应用程序陷入似乎无限循环的状态,此消息显示在控制台“twitterd会话中断,重启。”

该应用冻结了这行代码

if ([TWTweetComposeViewController canSendTweet])

非常感谢任何帮助。

////// EDIT ///////// 这是我的代码     if([TWTweetComposeViewController canSendTweet])     {         ACAccountStore * accountStore = [[ACAccountStore alloc] init];

// Create an account type that ensures Twitter accounts are retrieved.
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

// Request access from the user to use their Twitter accounts.
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
    if(granted) {
        // Get the list of Twitter accounts.
        NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];

        // For the sake of brevity, we'll assume there is only one Twitter account present.
        // You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present.
        if ([accountsArray count] > 0)
        {
            // Grab the initial Twitter account to tweet from.
            ACAccount *twitterAccount = [accountsArray objectAtIndex:0];


            NSURL *url = [NSURL URLWithString:@"http://api.twitter.com/1/account/verify_credentials.json"];
            TWRequest *req = [[TWRequest alloc] initWithURL:url
                                                 parameters:nil
                                              requestMethod:TWRequestMethodGET];

            // Important: attach the user's Twitter ACAccount object to the request
            req.account = twitterAccount;

            [req performRequestWithHandler:^(NSData *responseData,
                                             NSHTTPURLResponse *urlResponse,
                                             NSError *error) {

                // If there was an error making the request, display a message to the user
                if(error != nil) {

                }

                // Parse the JSON response
                NSError *jsonError = nil;
                id resp = [NSJSONSerialization JSONObjectWithData:responseData
                                                          options:0
                                                            error:&jsonError];

                // If there was an error decoding the JSON, display a message to the user
                if(jsonError != nil) {

                    return;
                }




            }];


        }
    }
}];
 }

1 个答案:

答案 0 :(得分:-1)

使用此代码检查Twitter帐户是否存在: -

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");

            }
            }

希望它可以帮到你!