2011-12-11 136 views
2

我創建了一個簡單的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請求必須活到賬戶請求。

回答

4

我解決了與我的TWRequest相似的問題,只需將ACAccountStore保留在實例變量中。