Discussion Forums  >  Config Data, JSON, App Refresh

Replies: 4    Views: 129

ThomasB
Lost but trying
Profile
Posts: 162
Reg: Jun 23, 2011
Palo Alto
3,270
07/16/13 03:46 PM (10 years ago)

Report to cloud...Different version (and auto-update) for each image?

I have a client who has a *lot* of images which change frequently. In their industry, the standard approach for apps is to automatically refresh all photos each time the app is re-started. Currently, buzz touch apps only have a single "report to cloud" version number, which if updated, causes the entire app (including config.txt and images) to be refreshed. This would be unworkable for the client, because refreshes would be wayyy too slow. I want to create a report to cloud version number for *each* downloadable image, so each image can be updated independently in each screen, without refreshing the rest of the app. Anybody done this? Can this even be done with the BT app architecture?
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
07/16/13 04:02 PM (10 years ago)
I wouldn't look at 'report to cloud', that just isn't going to work for you. To facilitate 'fresh' weather information in my 'SmugClimate' weather plugin, I named my files 'per hour' (10am: weather_10.txt, 5pm: weather_17.txt, etcetera) and deleted all other cached files with this code: -(void)deleteAllFilesButThisOne:(NSString *)saveThisFile { [BT_debugger showIt:self theMessage:[NSString stringWithFormat:@"Not Deleting: %@", saveThisFile]]; NSString *fragment = @"weather_??.txt"; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF like %@", fragment]; NSFileManager *fileManager = [NSFileManager defaultManager]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSArray *contents = [fileManager contentsOfDirectoryAtPath:documentsDirectory error:NULL]; NSArray *targetFile = [contents filteredArrayUsingPredicate:predicate]; NSEnumerator *e = [targetFile objectEnumerator]; NSString *filename; while ((filename = [e nextObject])) { if (![filename isEqualToString:saveThisFile]) { [fileManager removeItemAtPath:[documentsDirectory stringByAppendingPathComponent:filename] error:NULL]; [BT_debugger showIt:self theMessage:[NSString stringWithFormat:@"Deleting File: %@", filename]]; } } } This allowed me to keep the current file in cache, and get rid of the old files so they didn't take up needless space. But it could easily be converted to other uses... The way it works is, the system will get a list of files in your app document directory (Not to be confused with BT_Docs; not the same place), look for filenames with a particular pattern, and delete them. It's possible you may want to delete all cached image files on app startup, and just let each 'refresh' when the screen becomes active. Just simplify the pattern to the kind of image you're using, and try it out. Cheers! -- Smug Edit: the above code is for iOS. I'm sure something similar can be done on Android as well, I just haven't gotten there yet.
 
ThomasB
Lost but trying
Profile
Posts: 162
Reg: Jun 23, 2011
Palo Alto
3,270
like
07/16/13 04:29 PM (10 years ago)
Thank you... That's useful code, let me try it. My key issue is, any one of the these images will might hang around for a few weeks, and then one day, will suddenly need to be updated with a new version. So I'm thinking the steps are: 1. Have this dictionary that tracks every image, 2. Save a version number in the dictionary for each image name, 3. Each time I enter a given screen, check the version for the image in that screen compared to the newest version in the server, 4. If the server has a newer version, then transparently download that particular image and save it to the cache, before displaying. I think that's it :)
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
07/16/13 04:39 PM (10 years ago)
I actually can't think of exactly 'how' just yet, but I get the feeling that Stobe's 'JSON Snippet Keeper' could also play a positive role in this scenario... If you haven't worked with it before, it's kind of a 'swiss army knife' of Json potential, if used correctly. And it works in both iOS/Android, because it's not actually code; it's json. Cheers! -- Smug
 
Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
like
07/17/13 07:19 PM (10 years ago)
Lets point Warren at this and see if this is one of those 20-min videos for David to solve. I sent him a Private Message request. -- Niraj
 

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.