0

这是我的代码

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

}];

方法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;
}

正如调试器所说,该帐户已正确返回,但是当我在控制台中打印它时,我什么也没得到,一个空格;但是帐户对象有一个引用。

就在请求开始执行后,我收到一个 EXC_BAD_ACCESS 错误。堆栈说发送错误消息时发生错误[ACAccount accountType]

很明显这是一个内存问题,而且我是 ARC 的新手,所以我想问题会在那里。

有什么帮助吗?

4

1 回答 1

1

我不知道为什么我必须这样做,但是如果我为 ACAccountStore 声明一个实例变量以保留并以这种方式更改方法

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

一切都很完美。为什么?:\

于 2012-09-12T14:07:27.363 回答