【发布时间】:2011-12-11 17:44:18
【问题描述】:
我创建了一个简单的 Twitter 管理器,用作模型。
对于这个模型,我添加了一个属性“帐户”来存储 ACAccount ......现在,如果我尝试像此处显示的代码一样启动 Api 请求,我会得到一个EXC_BAD_ACCESS:
-(void)requestFollowers{
// Build a twitter request
TWRequest *followersRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:URL_FOLLOWERS]
parameters:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:self.account.username,@"-1",nil]
forKeys:[NSArray arrayWithObjects:@"screen_name",@"cursor",nil]] requestMethod:TWRequestMethodGET];
[followersRequest setAccount:self.account];
[followersRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
//DO SOMETHING
}];
}
虽然每当我在帐户请求中启动相同的方法时,它都会起作用...
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted){
NSArray *arrayOfAccounts = [accountStore accountsWithAccountType:accountType];
if ([arrayOfAccounts count] > 0)
{
self.account = [arrayOfAccounts objectAtIndex:0];
//HERE I LAUNCH PREVIOUS SHOWED METHOD
[self requestFollowers];
}
}
}];
因此,我在问是否每个 API 请求都必须包含在帐户请求中。
【问题讨论】: