I have set up my application so that every the application enters the foreground, it does a web call which calls information from a web server, where it receives and parses JSON, then stores it offline.
My application is a tabbed application, and each screen the information is set up from the JSON, and the images are also pulled from a server. So I want the information on each page to update after this is done, but its not updating.
I am running my application from the simulator for the time being incase that makes any difference. At present only way I can get the information to update is either use that viewDidAppear or stop and start the application again from xCode.
I tried calling the classes viewDidLoad from the AppDelegates
- (void)applicationWillEnterForeground:(UIApplication *)application
{
/*
Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
*/
WebCalls *wc = [[WebCalls alloc] init];
DashboardVC *db = [[DashboardVC alloc] init];
[wc setWebCallDidFinish:^(NSString * json, NSString *ID) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex: 0];
NSString *docFile = [docDir stringByAppendingPathComponent: @"json.txt"];
[json writeToFile:docFile atomically:NO encoding:NSUTF8StringEncoding error:Nil];
NSString *docDir2 = [paths objectAtIndex: 0];
NSString *docFile2 = [docDir2 stringByAppendingPathComponent: @"theID.txt"];
[ID writeToFile:docFile2 atomically:NO encoding:NSUTF8StringEncoding error:Nil];
[db testme];
}];
[wc getData];
}
This calls the viewDidLoad again, but the information doesn't update. Any ideas why?
Edit: In that class, it reads the JSON like this
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex: 0];
NSString *docFile = [docDir stringByAppendingPathComponent: @"json.txt"];
[json writeToFile:docFile atomically:NO encoding:NSUTF8StringEncoding error:Nil];
I can print the JSON out, and the JSON is definitely updating, but the information on the screen is not.
Edit: Updated with web call