AFNetworking: Can't Get New Data After A POST Request

201 Views Asked by At

I'm new with AFNetworking so I've never faced this problem before with NSURLConnection

I'm using this method after a post request to add category

-(void)getCategories{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSString * url = [NSString stringWithFormat:@"%@v2/api/tags",kURL];
    NSDictionary *parameters =[self parameterBuild];
    [manager GET:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        categories = [[NSMutableArray alloc]init];
        categories = [responseObject objectForKey:@"tags"];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", error);
    }];

}

And the problem is.. responseObject is always getting the old data for a while as if it's caching or something..

any help will be appreciated

1

There are 1 best solutions below

3
On

The problem comes, because you're not cleaning up the data and reloading view on error.

-(void)getCategories{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSString * url = [NSString stringWithFormat:@"%@v2/api/tags",kURL];
    NSDictionary *parameters =[self parameterBuild];
    [manager GET:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        categories = [[responseObject objectForKey:@"tags"] mutableCopy];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", error);
        categories = [NSMutableArray new];
        // Reload view here, like you do for success
    }];
}