0

This is my code

TWRequest *twRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", kTwitterURLBase, kTwitterMethodHelpConfiguration]]
                                           parameters:nil
                                        requestMethod:TWRequestMethodGET];

[twRequest setAccount:[self twitterAccount]];

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

     // Handling

}];

The method twitterAccount

- (ACAccount *)twitterAccount {

    NSString *identifier = [[Session getInstance] selectedAccountIdentifier];
    ACAccount *account = nil;

    if ([identifier length] > 0) {

        ACAccountStore *accountStore = [[ACAccountStore alloc] init];
        account = [accountStore accountWithIdentifier:identifier];
    }

    return account;
}

As debugger says, the account is correctly returned but when I print it in the console I get nothing, a blank space; but the account object has a reference.

Just after the request begins to be performed I get an EXC_BAD_ACCESS error. The stack says that the error occurs when sending a wrong message [ACAccount accountType].

It's obvious that is a memory problem, and I new with ARC so I guess that the problem would be there.

Any help?

emenegro
  • 6,901
  • 10
  • 45
  • 68

1 Answers1

1

I don't know why the hell I have to do this but if I declare an instance variable for the ACAccountStore to be retained and change the method this way

- (ACAccount *)twitterAccount {

    NSString *identifier = [[Session getInstance] selectedAccountIdentifier];
    ACAccount *account = nil;

    if ([identifier length] > 0) {

        if (accountStore_ == nil) {

            accountStore_ = [[ACAccountStore alloc] init];
        }

        account = [accountStore_ accountWithIdentifier:identifier];
    }

    return account;
}

all goes perfect. Why? :\

emenegro
  • 6,901
  • 10
  • 45
  • 68
  • Had the same error. Your answer fixed it but I still don't know exactly why :) – WalterF Sep 12 '12 at 14:18
  • Oh man, I've just had the same issue with a CLLocationManager, and it was fixed the same way. Maybe I'm doing something wrong because I don't understand anything :\ – emenegro Sep 12 '12 at 14:50
  • The docs say that an `ACAccount` is related to an `ACAccountStore`. So you should hold onto the account store for as long as you need the account. – mattjgalloway Feb 06 '13 at 09:36