Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Business Forums > Business, Legal, & App Store

Reply
 
LinkBack Thread Tools Display Modes
Old 10-07-2010, 09:36 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 38
mtbennett24 is on a distinguished road
Default App Updates

Hello,

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.

Thank you
mtbennett24 is offline   Reply With Quote
Old 10-07-2010, 10:24 PM   #2 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 916
lukeca is on a distinguished road
Default

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.
lukeca is offline   Reply With Quote
Old 10-07-2010, 10:35 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 38
mtbennett24 is on a distinguished road
Default

Quote:
Originally Posted by lukeca View Post
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?
mtbennett24 is offline   Reply With Quote
Old 10-07-2010, 10:50 PM   #4 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,971
Bertrand21 is on a distinguished road
Default

Quote:
Originally Posted by mtbennett24 View Post
Is there a specific way to install the update from Xcode? Or is it the same as doing a Build and Debug?
Build and debug or run
__________________
Haters gonna Hate
Likers gonna Like
Bertrand21 is offline   Reply With Quote
Old 10-08-2010, 10:51 AM   #5 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 38
mtbennett24 is on a distinguished road
Default

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?
mtbennett24 is offline   Reply With Quote
Old 10-08-2010, 11:17 AM   #6 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 38
mtbennett24 is on a distinguished road
Default

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.
mtbennett24 is offline   Reply With Quote
Old 10-08-2010, 11:29 AM   #7 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 916
lukeca is on a distinguished road
Default

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.
lukeca is offline   Reply With Quote
Old 10-08-2010, 11:51 AM   #8 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 38
mtbennett24 is on a distinguished road
Default

Code:
// '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?
mtbennett24 is offline   Reply With Quote
Old 10-08-2010, 12:19 PM   #9 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 916
lukeca is on a distinguished road
Default

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?
lukeca is offline   Reply With Quote
Old 10-08-2010, 12:25 PM   #10 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

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?
JasonR is offline   Reply With Quote
Old 10-08-2010, 12:30 PM   #11 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 38
mtbennett24 is on a distinguished road
Default

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.
mtbennett24 is offline   Reply With Quote
Old 10-08-2010, 12:41 PM   #12 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

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?
JasonR is offline   Reply With Quote
Old 10-08-2010, 01:03 PM   #13 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 155
barrettj is on a distinguished road
Default

Quote:
Originally Posted by mtbennett24 View Post
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).

Last edited by barrettj; 10-08-2010 at 01:05 PM.
barrettj is offline   Reply With Quote
Old 10-08-2010, 01:11 PM   #14 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 38
mtbennett24 is on a distinguished road
Default

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:

Code:
- (void) copyDatabaseIfNeeded {
	NSFileManager *fileManager = [NSFileManager defaultManager];
	NSError *error;
	NSString *dbPath = [self getDBPath];
	BOOL success = [fileManager fileExistsAtPath:dbPath];
	
	if(!success) {
		
		NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"iflyguide.sqlite"];
		success = [fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error];
		
		if (!success)
			NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
	}
}

- (NSString *) getDBPath {
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
	NSString *documentsDir = [paths objectAtIndex:0];
	return [documentsDir stringByAppendingPathComponent:@"sql.sqlite"];
}
mtbennett24 is offline   Reply With Quote
Old 10-08-2010, 01:13 PM   #15 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 38
mtbennett24 is on a distinguished road
Default

Quote:
When you say run the app again - are you sure you're quitting the application and not just backgrounding it and resuming it?
I am quitting the app by using the Home button on the device or terminating the debug session in Xcode. Thanks!
mtbennett24 is offline   Reply With Quote
Old 10-08-2010, 03:45 PM   #16 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 38
mtbennett24 is on a distinguished road
Default

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:

/var/mobile/Applications/ADE2D7D1-xxxx-xxxx-xxxx-xxxxxxxxxxxx/

And when I made a change to the code and did a Build and Run again, the absolute path to the app changed to:

/var/mobile/Applications/3DB46559-xxxx-xxxx-xxxx-xxxxxxxxxxxx/

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.
mtbennett24 is offline   Reply With Quote
Old 10-11-2011, 01:54 PM   #17 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 21
famictech2000 is on a distinguished road
Default

Quote:
Originally Posted by mtbennett24 View Post
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:

Code:
- (void) copyDatabaseIfNeeded {
	NSFileManager *fileManager = [NSFileManager defaultManager];
	NSError *error;
	NSString *dbPath = [self getDBPath];
	BOOL success = [fileManager fileExistsAtPath:dbPath];
	
	if(!success) {
		
		NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"iflyguide.sqlite"];
		success = [fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error];
		
		if (!success)
			NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
	}
}

- (NSString *) getDBPath {
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
	NSString *documentsDir = [paths objectAtIndex:0];
	return [documentsDir stringByAppendingPathComponent:@"sql.sqlite"];
}
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?
famictech2000 is offline   Reply With Quote
Old 10-11-2011, 02:55 PM   #18 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 38
mtbennett24 is on a distinguished road
Default

Quote:
Originally Posted by famictech2000 View Post
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.
mtbennett24 is offline   Reply With Quote
Old 10-28-2011, 04:39 PM   #19 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 21
famictech2000 is on a distinguished road
Default Update sqlite DB fianl question hopefully :)

Quote:
Originally Posted by mtbennett24 View Post
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.
famictech2000 is offline   Reply With Quote
Old 10-31-2011, 12:22 PM   #20 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 38
mtbennett24 is on a distinguished road
Default

Quote:
Originally Posted by famictech2000 View Post
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
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.
mtbennett24 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 175,641
Threads: 94,108
Posts: 402,847
Top Poster: BrianSlick (7,990)
Welcome to our newest member, JmacDotOrg
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:49 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0