1

iOS 5 で twitter を使用してシングル サインオンを実装しようとしていますが、settings.app にアカウントがない場合を除き、すべて正常に動作しています。アプリケーションは無限ループのように見え、このメッセージがコンソールに表示されます"twitterdセッションが中断されました。再開します。」

このコード行でアプリがフリーズします

if ([TWTweetComposeViewController canSendTweet])

どんな助けでも本当に感謝しています。

//////EDIT///////// これ が私のコードです。

// 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;
                }




            }];


        }
    }
}];
 }
4

1 に答える 1

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

            }
            }

お役に立てば幸いです。

于 2012-11-05T09:38:16.793 に答える