每个Twitter API请求都必须存在ACAccount请求吗?
问题描述:
我创建了一个简单的Twitter管理器,用作模型。 对于这个模型我添加了一个属性“帐户”来存储ACAccount ......现在,如果我尝试推出像这里显示的代码API请求我得到一个EXC_BAD_ACCESS
:每个Twitter API请求都必须存在ACAccount请求吗?
-(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请求必须活到账户请求。
答
我解决了与我的TWRequest相似的问题,只需将ACAccountStore保留在实例变量中。