issue with EXC_BAD_REQUEST in TWRequest

913 views Asked by At

I have the following code and it always gives me a crash when performing the request, any idea?

NSString *responseBody = [[NSString alloc] initWithData:data
                                                       encoding:NSUTF8StringEncoding];

        NSLog(@"Response body is %@", responseBody);

        NSDictionary *accessTokenRequestParams = [[NSMutableDictionary alloc] init];
        [accessTokenRequestParams setValue:CONSUMER_KEY forKey:@"x_reverse_auth_target"];
        [accessTokenRequestParams setValue:responseBody forKey:@"x_reverse_auth_parameters"];            

        NSURL *url2 = [NSURL URLWithString:@"https://api.twitter.com/oauth/access_token"];
        TWRequest * accessTokenRequest = [[TWRequest alloc] initWithURL:url2 parameters:accessTokenRequestParams requestMethod:TWRequestMethodPOST];


        if (selectionIndex != -1)
            [accessTokenRequest setAccount:[self.twitterACAccounts objectAtIndex:selectionIndex]];

        // execute the request
        [accessTokenRequest performRequestWithHandler:
         ^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
             NSString *responseStr = 
             [[NSString alloc] initWithData:responseData 
                                   encoding:NSUTF8StringEncoding];

            NSLog(@"The user's info for your server:\n%@", responseStr);
         }];

UPDATE: Turning on NSZombieEnabled gives me

*** -[ACAccountStore typeForAccount:]: message sent to deallocated instance 0x7199c70

this is no where to be found

2

There are 2 answers

0
AAV On BEST ANSWER

Your error looks completely different than your question. You have error in ACAccountStore class. Check your retain count when you accessing, manipulating, and store accounts (ACAccountStore). I think you are deallocated memory first and you are using some where.

0
Tom Andersen On

Somewhere you call ACAccountStore typeForAccount. But the ACAccountStore is gone. Looking at the AcAccount docs, there are no special initializers, so likely in your code you have something like:

static ACAccountStore* accountStore = [[[ACAccountStore alloc] init] autorelease];

then in the completion for the request, the object has been cleaned away by the OS, but your accountStore still points to the old, now dangling pointer. The pointer may be 'static' or 'global' or a member of some other static or global object.

Look for ACAccountStore in your code.