我创建了一个简单的Twitter管理器作为模型。 对于此模型,我添加了一个属性“ account”来存储ACAccount ...现在,如果我尝试启动Api请求(如此处所示的代码), EXC_BAD_ACCESS得到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的请求都必须包含在帐户请求中。

===============>>#1 票数:4 已采纳

通过将ACAccountStore保留在实例变量中,我解决了TWRequest的类似问题。

  ask by MatterGoal translate from so

未解决问题?本站智能推荐:

关注微信公众号