Reputation: 41
In my application I have saved videos and photos in document directory and photos and videos url path store in sqlite. While updating (Upgrading) the iPhone Application all document directory photos and videos are deleted. But other parameters stored in sqlite not deleted. How to I retain the files while updating the app?
-(BOOL)saveImageToDocumentDirectory:(UIImage*)imgToBeSaved { BOOL flag = NO;
strPhotourl=nil;
NSData* imgData = UIImageJPEGRepresentation(imgToBeSaved, 1.0);
// NSData *imgData1=UIImagePNGRepresentation(imgToBeSaved);
// Create a new UUID
CFUUIDRef uuidObj = CFUUIDCreate(nil);
// Get the string representation of the UUID
NSString *strImageName = (__bridge NSString*)CFUUIDCreateString(nil, uuidObj);
CFRelease(uuidObj);
//Call Function to save image to document directory
NSArray* arrAllDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* strDocumentDirectory = [arrAllDirectories objectAtIndex:0];
NSFileManager* fileManager = [NSFileManager defaultManager];
NSString *fullPath = [strDocumentDirectory stringByAppendingPathComponent:[strImageName stringByAppendingString:@".png"]];
strPhotourl=fullPath ;// strPhotourl store in sqlite db table two show images in tableview
// NSLog(@"Image in strphotolocation==%@",imagePath);
// NSLog(@"fullpath---%@",fullPath);
if(![fileManager fileExistsAtPath:fullPath])
flag = [fileManager createFileAtPath:fullPath contents:imgData attributes:nil];
else
flag = NO;
return flag;
}
Upvotes: 3
Views: 2769
Reputation: 4427
The reason is not because any files were deleted but because the folder an iOS app resides in does change during an upgrade. The folder your app is stored in is named using a GUID, and this may change on an upgrade.
You should not store the full URL/PATH to any files in your Documents folder, as this is not guaranteed to remain after an upgrade.
Files Saved During App Updates
When a user downloads an app update, iTunes installs the update in a new app directory. It then moves the user’s data files from the old installation over to the new app directory before deleting the old installation. Files in the following directories are guaranteed to be preserved during the update process:
- Application_Home/Documents
- Application_Home/Library
Although files in other user directories may also be moved over, you should not rely on them being present after an update.
If you already have the app deployed on users phones, then what you could do is when you read the url from sqlite, remove the leading path (eg: /var/mobile/Applications/---guid---/Documents) and then re-save the entry before using it.
Upvotes: 8
Reputation: 859
Don't save the entire path into sqlite,just save the file name which you are stored in local so while fetching, get the current directory path and append with fileName from sqlite. This will solve when you upgrading your app also.
Upvotes: 4