While updating the Application all local files are deleted in iPhone

ios, objective-c

Solution

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.

Problem

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; ``` }

Original source