Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSURLConnection does not refresh

I have a NSURLConnection which I am calling every time -(void)viewWillAppear:animated is called (that's only for now, it's just for testing)

I am doing it like this

receivedData = [[NSMutableData data] retain];
NSString *urlString = @"<URL hidden>";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30.0];
[NSURLConnection connectionWithRequest:request delegate:self];

Then I have these three delegate methods:

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [receivedData appendData:data];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSString *returnString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
    usersPhotos = [[NSMutableArray alloc] initWithArray:[[returnString JSONValue] objectForKey:@"data"]];
    [self loadAnnotations];

    NSLog(@"%@", returnString);

    [returnString release];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    [self loadAnnotations];
}

Even though I am sure the returnStringshould change (I can visit the site in urlString and confirm it has changed) it is always the same.

It is as if it reuses the data that it retrieves from the first connection.

Does anyone know why this is?

like image 560
simonbs Avatar asked Sep 12 '26 11:09

simonbs


1 Answers

it should be your cache policy, i will update in a second with the correct info.


UPDATE

Try setting your cahce policy to: cachePolicy:NSURLRequestReloadIgnoringCacheData

It should be:

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0];
like image 171
Nicolas S Avatar answered Sep 14 '26 01:09

Nicolas S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!