在我的应用程序中,我将视频和照片保存在文档目录中,并将照片和视频 url 路径存储在 sqlite 中。在更新(升级)iPhone 应用程序时,所有文档目录中的照片和视频都会被删除。但是存储在sqlite中的其他参数没有被删除。如何在更新应用程序时保留文件?
-(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;
}