I am new to the app store process and was wondering about app updates. When I update my app and it is made available in the app store, is the entire app reloaded on the user's device? Will they lose all/any files that might have been written to the app's home directory? If I am using an SQLite db, will that be overwritten? Or is simply the binary file updated? Any app update pointers are greatly appreciated as I haven't been able to locate any documentation on the subject.
Items in the app's home directory are not overwritten with updates. It's always a good idea to test your update yourself. Download the existing version from the app store then install the updated version from Xcode over the app store version and make sure things work correctly.
Download the existing version from the app store then install the updated version from Xcode over the app store version and make sure things work correctly.
Is there a specific way to install the update from Xcode? Or is it the same as doing a Build and Debug?
When testing and debugging my app, I notice when I do a Build and Debug, my SQLite db remains in tact from /Documents from the last launch, but all of the image files written to /Documents are gone. Thoughts?
To follow up, when I perform a 'Build and Debug' my SQLite DB saved to /Documents remains intact. However, all of my image files written to /Documents are removed. If I perform a 'Run', the SQLite DB AND images remain intact. So when you update your app from the app store, will it function more like 'Build and Debug' or 'Run'? I just want to make sure that any files saved to /Documents remain intact after app updates from the app store. Thank you.
The closest you can get to how it will run from the app store is setting your configuration to "Release" and then using Build and Run.
Although either way it seems odd that it is deleting files in the home directory, these are images that your app actually copied into that directory? Do you have some code that is maybe deleting them somehow? I can tell you that Build and Debug has never deleted anything that I actually saved myself.
// 'img' is a UIImage in the view
NSData *imageData = UIImageJPEGRepresentation(img, 0.8);
NSString *imageName = [NSString stringWithFormat:@"image%@.jpg", stringImageID];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];
[imageData writeToFile:fullPathToFile atomically:YES];
This is the code I am using to write the file to the /Documents directory. With the configuration set to 'Debug', 'Build and Run' seems to work and will not delete the images saved to /Documents until XCode has to install the app on the device. So if there are no code changes, 'Build and Run' does not delete files. If there are code changes, 'Build and Run' re-installs the app on the device (which I imagine is like an app update) and the images are gone. What is strange is that the SQLite DB that is written to the same directory remains intact. There is no code that removes files from /Documents. Is there a better method for copying/writing files to /Documents?
That seems fine to me, maybe someone else will chime in, just seems odd that it deletes the images but leaves your database. I'm just not really sure why it would do that.
What happens if you download the version from the appstore, create some images and save them, and then install the version from xcode. Do the images get deleted?
My suspicion would be that the images are still there, but you are losing track of your imageID's so that you can't find them any more. How are you keeping track of them?
The image paths are stored in an SQLite db. When I run the app, save images, quit the app, run the app again without xcode everything works fine. I have NSLog statemtents checking if the file exists and it is only when I perform a 'Build and Run' and the app is re-installed on the device do the NSLog statements return NO when checking for file existance.
This is what I would expect if you were saving the images in the cache directory, not the documents directory. I've definitely seen files still in the documents directory after 'Build and Run' for both Debug and Release. In my case they were video files, but there's nothing special about image files. So there must be something else deleting the files.
Where in your code are you checking for the files? Could there be something happening before that to delete them? Also, how are you saving the filenames in the DB?
The image paths are stored in an SQLite db. When I run the app, save images, quit the app, run the app again without xcode everything works fine. I have NSLog statemtents checking if the file exists and it is only when I perform a 'Build and Run' and the app is re-installed on the device do the NSLog statements return NO when checking for file existance.
When you say run the app again - are you sure you're quitting the application and not just backgrounding it and resuming it?
I can also attest to the fact the what's in the documents directory stays in the documents directory (until I delete the app entirely) for me (both on iPads and iPhones, simulated and actual).
As far as I can tell when testing the app, the images are saved correctly in the /Documents directory and in the DB. It is only when the app is re-installed on the device that they are deleted. If the problem was in the code, I was thinking I would see images deleted on app re-launch. But when I run the app outside of Xcode, save images, quit, re-launch outside of Xcode everything works great. It is only when the code is re-compiled and the app is re-installed on the device from Xcode that the images in the /Documents folder are removed. What is strange is that the SQLite DB file that is saved in /Documents remains intact. And for that I am using:
So it turns out, when I was running my app and saving images to the Documents directory, I was saving the absolute path of the image in the SQL db. This worked on first install and run of the app. However on subsequent "Build and Runs" when the app was reinstalled, the absolute directory of the app was changing. So on first Build and Run the app directory was:
And continues to change everytime I change code and do a Build and Run. So the solution was to refrain from storing the absolute path to the image I was saving, and just save the file name, then prepend the Documents directory path at run time. Which makes me wonder, is my device now holding a bunch of different app directories when the app is re-installed on the device?
Thank you for you input.
Last edited by mtbennett24; 10-08-2010 at 04:50 PM.
As far as I can tell when testing the app, the images are saved correctly in the /Documents directory and in the DB. It is only when the app is re-installed on the device that they are deleted. If the problem was in the code, I was thinking I would see images deleted on app re-launch. But when I run the app outside of Xcode, save images, quit, re-launch outside of Xcode everything works great. It is only when the code is re-compiled and the app is re-installed on the device from Xcode that the images in the /Documents folder are removed. What is strange is that the SQLite DB file that is saved in /Documents remains intact. And for that I am using:
OK so that is the funtion you worte , but where and when do you call this, and how do you deterimine when the app needs to update the database and execute the funtions above?
OK so that is the funtion you worte , but where and when do you call this, and how do you deterimine when the app needs to update the database and execute the funtions above?
I call the copyDatabaseIfNeeded method from within the applicationDidFinishLaunching method in the app delegate.
I call the copyDatabaseIfNeeded method from within the applicationDidFinishLaunching method in the app delegate.
Final question hopefully....
OK so now I have where you call the function, but if you place it in applicationDidFinishLaunching, do you have any logic to see when it has to update the existing sqlite db? If you have it in applicationDidFinishLaunching, won't it just update the sqlite db everytime the app launches, instead of just when the app has been updated?
In other words: Ex. V1.0 of app I have a sqlite db with info, on v2.0 I have the same named sqlite db but it has more info (maybe changed some tables and added more info - content) would the same approach work?
Frank
Last edited by famictech2000; 10-28-2011 at 04:42 PM.
OK so now I have where you call the function, but if you place it in applicationDidFinishLaunching, do you have any logic to see when it has to update the existing sqlite db? If you have it in applicationDidFinishLaunching, won't it just update the sqlite db everytime the app launches, instead of just when the app has been updated?
In other words: Ex. V1.0 of app I have a sqlite db with info, on v2.0 I have the same named sqlite db but it has more info (maybe changed some tables and added more info - content) would the same approach work?
Frank
In this case perhaps you could set a Boolean flag stating whether the DB has been updated to v2.0. Then write that Boolean to disk so that on app startup it would check to see if the Boolean is set to true. If not, it would update the DB on startup. Not sure if that is the most efficient solution.