objective c - Background fetch not updating UI -


I'm new to bring ios7 background

Note that here I am storing the entire JSON file in a string so that I can check the new content.

  - (void) application: (UIApplication *) applications performFetchWithCompletionHandler: (a zero (^) (UIBackgroundFetchResult)) completed Hondlr {// HomepageView view controller should update that HomepageView * homepage = [[HomepageView alloc] init]; NSURL session configuration * sessionConfiguration = [NSURL session configuration default session configuration]; NSURL session * session = [configuration with NSURL session session: session configuration]; NSDRL * URL = [[NSWRLLO] InitvithString: @ "http://sample.com/api/home/lastnews"]; Newsson = [NSString stringWithContentsOfURL: URL encoding: NSUTF8 string encoding error: zero]; NSURLSessionDataTask * task = [session Detatosk with url: url completionHandler: ^ (NSData * data, NSURLResponse * reaction, NSError * error) {if (error) {completionHandler (UIBackgroundFetchResultFailed); Return; } If (! [Newzan Avlastostring: Old Jason]) {FullHandler (UI Backfirst Result New Data); NSLog (@ "New Data:% @", New Jersey); } Else {completionHandler (UIBackgroundFetchResultNoData); NSLog (@ "Old Jason:% @", Old Jason); }}]; // Start the job [start the work again]; }  

Now to test the entire process, I just run the application. Then I send it in the background and then when I have the new content in the JSON file, I work to bring the simultaneous background from the debug menu. Then I open the application, but nothing will change.

First of all, NSUserDefaults as seen below

< Pre> if (! [New Zeben Evoltostring: Old Jason]) {completionHandler (UIBackgroundFetchResultNewData); NSLog (@ "New Data:% @", New Jersey); NSUserDefaults * defaults = [NSUserDefaults Standard User Default]; [Default set object: New Jersey Foreke: @ "Newsson"]; }

Add your second it ViewDidLoad

  [[NSNotificationCenter defaultCenter] addObserver: self selector: @ selector (Fresh :) Name: UIApplicationWillEnterForegroundNotification object: zero];  

Add it to your viewWillAppear

  - (zero) viewer applet: (BOOL) animated {[self loadData]; }  

Loddeta create include

  - (minus) Loddeta {// Check controller uses NSUserDefaults * defaults = [NSUserDefaults StandardUserDefaults] ; TextView.text = [Default ObjectForrechy: @ "Newsson"]; }  

Finally add your action

  - (IBAction) Refresh: (ID) sender {nslog (@ "i ran"); [Self-loaded data]; }  

I tested it and it works.


Comments