simusid
simusid

Reputation: 1904

NSURLRequest in viewDidLoad using cached data?

I populate a tableView in my viewDidLoad to get some JSON from my server.

NSURL *theEvents = [NSURL URLWithString:@"http://192.168.1.100:3000/events.json"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:theEvents cachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:60.0];

NSHTTPURLResponse *response = nil;
NSData *data  = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

When I debug and run this code it gets live data from the server. If I stop (the debugger) and start again it also works fine and gets live data from the server. However if I:

  1. start the app (data is retrieved fine)
  2. stop the app in the simulator (simulator stays running)
  3. change the data on the server
  4. start the app again in the simulator (that is run it from the simulator screen

it does not get the live changed data from the server. I don't understand this. When I quit the app in the simulator via the home button, doesn't the program completely exit? I get the exact same behavior with a phone too.

I want to always get live data from my server in viewDidLoad. What am I doing wrong?

Upvotes: 1

Views: 141

Answers (1)

simusid
simusid

Reputation: 1904

This is exactly what fixed my problem:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(wokeUp) name:UIApplicationDidBecomeActiveNotification object:nil];

Upvotes: 1

Related Questions