首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ACAccount和TWRequest出错

ACAccount和TWRequest出错
EN

Stack Overflow用户
提问于 2012-09-12 21:33:02
回答 1查看 339关注 0票数 0

这是我的代码

代码语言:javascript
复制
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方法

代码语言:javascript
复制
- (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;
}

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

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

很明显,这是一个内存问题,我刚接触ARC,所以我猜问题应该在那里。

有什么帮助吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-12 22:07:27

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

代码语言:javascript
复制
- (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;
}

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12389372

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档