Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 24    Views: 153

mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
Fourm StarFourm StarFourm Star
03/17/15 12:46 PM (7 years ago)

Age old question: force refresh upon first launch :-) [solved]

Hi folks! Working on an conference app, it's vital that the users who launch this app get the latest config right-then-and-there, if they see outdated information, that could be *extremely* bad. I'm not using custom URL's or any other content that can be updated online, it's all in the app, so a refresh is vital. There are ***tons*** of buzztouch thread requests for forcing a refresh upon launch, but a total of 0 solutions as far as I can tell. The idea is that they launch the app (first time, and every time after), they see a screen that says "updating conference information", it triggers a refresh, and it pushes to a specified screen. Having loads of trouble getting this done for someone that likes to think he's able to hack away at BT's code pretty well by now.. LOL! Any help is appreciated - please no suggestions for alternatives, really - the way I have it all set up, it **needs** to be able to refresh the config upon first launch of the app. Many thanks fellow BT'ers! Note: the automatic refresh PDF only makes it so that it doesnt ask the user, it has nothing to do with refreshing the app upon first launch after install from the app store. I'll need the solution to work for Android too, if possible. Thanks again! David.
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
Fourm StarFourm StarFourm Star
like
03/17/15 01:02 PM (7 years ago)
I have a solution in mind, but have yet to test it, I'll let you folks know if it works. Step 1: The app launches for the first time. It checks to see if a local text file has the value 0 (it will). Step 2: If the value comes up as 0 or nil, it will change it to 1, then trigger a refresh. Simple as that. From there on, the text file and code that checks/writes to it is useless, it finished it's one time purpose - if it detects a 1, it won't do anything. BT should do what it usually does and check for a update every launch after the first one and then trigger refresh automatically. Betting this will work, but you never know until you try! David.
 
aussiedra
Code is Art
Profile
Posts: 431
Reg: Dec 25, 2010
Brisbane, Austr...
8,260
Fourm StarFourm Star
like
03/17/15 01:15 PM (7 years ago)
put [self refreshAppData]; here : -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ [BT_debugger showIt:self message:[NSString stringWithFormat:@"didFinishLaunchingWithOptions%@", @""]]; /* Debugging Output --------------------------------------------------------------------------- Set showDebugInfo to TRUE to print details to the console. To see the console, choose Run > Show Console while the simulator or a connected device is running. Nearly every method has output to show you details about how the program is executing. It looks like lots of data (it is), but it's very useful for understanding how the application is behaving. */ //show debug in output window? [self setShowDebugInfo:TRUE]; [self refreshAppData];
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
Fourm StarFourm StarFourm Star
like
03/17/15 01:27 PM (7 years ago)
Hi Aussie, Crashes the app, and not sure that would actually work correctly - since the app would find itself in a refresh loop - wouldn't it? Either way, error crash here: http://postimg.org/image/rs3hgj957/ Thanks mate :-) David
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
Fourm StarFourm StarFourm Star
like
03/17/15 01:32 PM (7 years ago)
So here's my newbish solution in code, for anyone interested, so far, it keeps detecting a 1 (or rather, it's not detecting a nil, which is weird, there's nothing written to it), so it won't refresh. http://pastebin.com/rPfKmLjR Scratching head. David.
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
Fourm StarFourm StarFourm Star
like
03/17/15 03:13 PM (7 years ago)
if you want to force refresh everytime the app is opened then the method you are looking for is - (void)applicationDidBecomeActive:(UIApplication *)application{ Change [self reportToCloud]; in app delegate line 179 to [self refreshAppData];
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
Fourm StarFourm StarFourm Star
like
03/17/15 03:35 PM (7 years ago)
Just read you wanted it makes sure resets on initial launch. The reason why it crashes using ausidras way is because the [self refreshappdata]; deletes the previous config as there isn't any it crashes. around line 240 in the app deleagate find [BT_fileManager deleteFile:[self saveAsFileName]]; and put this if statement around it //remove previously cached version of config data... if ([BT_fileManager doesFileExistInBundle:[self saveAsFileName]]) { [BT_fileManager deleteFile:[self saveAsFileName]]; } This checks if the old config is there, if it is it deletes it so the app will refresh.
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
Fourm StarFourm StarFourm Star
like
03/17/15 04:15 PM (7 years ago)
Hi Kittsy! Thanks, I made both modifications as you suggested - but I don't "notice" it refreshing when I open the app for the first time - or any other time it's launched. Weird. Thanks for all the help. David.
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
Fourm StarFourm StarFourm Star
like
03/17/15 04:16 PM (7 years ago)
Wait - it *does* refresh when opened any other time other than the first time, I wonder if it does it the first time but it just blends in with the regular loading. Hmmm. David.
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
Fourm StarFourm StarFourm Star
like
03/17/15 04:18 PM (7 years ago)
it definitely refreshes if you add the line ausidra posted and my fix
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
Fourm StarFourm StarFourm Star
like
03/17/15 04:22 PM (7 years ago)
Okay. Weird. It's definitely refreshing. But it's not actually grabbing the new config. No matter the changes I make, even a manual tap to the refresh icon, brings in no new config. David
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
Fourm StarFourm StarFourm Star
like
03/17/15 04:28 PM (7 years ago)
False alarm. It may be working. Testing now. :-) David
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
Fourm StarFourm StarFourm Star
like
03/17/15 04:34 PM (7 years ago)
Okay. Testing complete. 50% there. When launching for the first time, I can confirm, it refreshes and works beautifully. HOWEVER, when launching any other time, it refreshes, but does not actually update. Any ideas? David.
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
Fourm StarFourm StarFourm Star
like
03/17/15 04:50 PM (7 years ago)
scrap what we've done you are right it wasn't checking the cloud version. reset it to the beginning. First the initial loading go to bt_loadconfigdataviewcontroller.m line 140 change [self setNeedsRefreshed:FALSE]; to [self setNeedsRefreshed:TRUE]; The for the other on app opening remove lines 406 to 420 namely this //if value are not emtpy, and different....ask user to confirm refresh... if([lastModified length] > 3 && [previousModified length] > 3){ if(![lastModified isEqualToString:previousModified]){ //show alert with confirmation... UIAlertView *modifiedAlert = [[UIAlertView alloc] initWithTitle:nil message:NSLocalizedString(@"updatesAvailable", "This app's content has changed, would you like to refresh?") delegate:self cancelButtonTitle:NSLocalizedString(@"no", "NO") otherButtonTitles:NSLocalizedString(@"yes", "YES"), nil]; [modifiedAlert setTag:12]; [modifiedAlert show]; } }else{ [BT_debugger showIt:self theMessage:[NSString stringWithFormat:@"%@ does not exist in the cache. Not checking for updates.", self.modifiedFileName]]; } and put [self refreshAppData]; in it's place //connectionDidFinishLoading (handles report to cloud results)... -(void)connectionDidFinishLoading:(NSURLConnection *)connection{ connection = nil; //save data as "lastModified" file NSString *dStringData = [[NSString alloc] initWithData:receivedData encoding:NSASCIIStringEncoding]; if([dStringData length] > 3){ //returned data format: {"lastModifiedUTC":"2011-02-22 02:13:25"} NSString *lastModified = @""; NSString *previousModified = @""; //parse returned JSON data SBJsonParser *parser = [SBJsonParser new]; id jsonData = [parser objectWithString:dStringData]; if(jsonData){ if([jsonData objectForKey:@"lastModifiedUTC"]){ lastModified = [jsonData objectForKey:@"lastModifiedUTC"]; [BT_debugger showIt:self theMessage:[NSString stringWithFormat:@"lastModified (value on server): %@", lastModified]]; } } //parse previous saved data if([BT_fileManager doesLocalFileExist:self.modifiedFileName]){ NSString *previousData = [BT_fileManager readTextFileFromCacheWithEncoding:self.modifiedFileName encodingFlag:-1]; SBJsonParser *parser = [SBJsonParser new]; id jsonData = [parser objectWithString:previousData]; if(jsonData){ if([jsonData objectForKey:@"lastModifiedUTC"]){ previousModified = [jsonData objectForKey:@"lastModifiedUTC"]; [BT_debugger showIt:self theMessage:[NSString stringWithFormat:@"previousModified (value on device): %@", previousModified]]; } } } //save a copy of the lastModified text for next time.. BOOL saved = [BT_fileManager saveTextFileToCacheWithEncoding:dStringData fileName:self.modifiedFileName encodingFlag:-1]; if(saved){}; [self refreshAppData]; } }
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
Fourm StarFourm StarFourm Star
like
03/17/15 04:50 PM (7 years ago)
This definitely works lol
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
Fourm StarFourm StarFourm Star
like
03/17/15 04:51 PM (7 years ago)
This is what happens when your coding with a screaming baby in the next room
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
Fourm StarFourm StarFourm Star
like
03/17/15 04:56 PM (7 years ago)
Lol! Thanks! For your directions.. "and put [self refreshAppData]; in it's place " I did that, but then you posted more code at the bottom? You rock! David.
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
Fourm StarFourm StarFourm Star
like
03/17/15 04:58 PM (7 years ago)
Oh sorry, you're showing me what it's supposed to look like, duh, LOL! Testing! David.
 
aussiedra
Code is Art
Profile
Posts: 431
Reg: Dec 25, 2010
Brisbane, Austr...
8,260
Fourm StarFourm Star
like
03/17/15 05:08 PM (7 years ago)
sorry that worked on one of my app. hopefully Kittsy placement did the job.
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
Fourm StarFourm StarFourm Star
like
03/17/15 05:16 PM (7 years ago)
Works perfectly! Now I just need to get this working on the Android side! Kittsy, Aussie, I don't suppose you guys delved into Android have you? LOL! Totally fine if not, thanks so much for the help. David.
 
CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
Fourm StarFourm Star
like
03/17/15 07:44 PM (7 years ago)
Awesome thanks yall for the tip!
 
nadthevlad
Code is Art
Profile
Posts: 1025
Reg: Jun 07, 2012
Denver
21,850
Fourm StarFourm StarFourm Star
like
03/17/15 08:05 PM (7 years ago)
Nice, BOOKMARKING THIS
 
LeonG
Apple Fan
Profile
Posts: 694
Reg: Nov 08, 2011
Hamburg
17,740
Fourm StarFourm StarFourm Star
like
03/18/15 04:41 AM (7 years ago)
Big thx! Let us know if anyone finds a way to do that in Android as well! KUDOS
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
Fourm StarFourm StarFourm Star
like
03/18/15 08:46 AM (7 years ago)
Bahaha, heros you two are :-) David
 
Arubaman
Aspiring developer
Profile
Posts: 636
Reg: Oct 20, 2011
Akron
16,910
Fourm StarFourm StarFourm Star
like
03/18/15 11:49 AM (7 years ago)
Great discussion, I always enjoy the new code solutions.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.