gpt4 book ai didi

ios - 更新应用程序时,iPhone 中的所有本地文件都会被删除

转载 作者:行者123 更新时间:2023-12-01 17:26:15 25 4
gpt4 key购买 nike

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

-(BOOL)saveImageToDocumentDirectory:(UIImage*)imgToBeSaved 目录{ BOOL标志=否;

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);

if(![fileManager fileExistsAtPath:fullPath])
flag = [fileManager createFileAtPath:fullPath contents:imgData attributes:nil];
else
flag = NO;
return flag;

最佳答案

原因不是因为任何文件被删除,而是因为 iOS 应用所在的文件夹在升级过程中确实发生了变化。您的应用程序所在的文件夹使用 GUID 命名,这可能会在升级时发生变化。

您不应将完整的 URL/PATH 存储到 Documents 文件夹中的任何文件,因为升级后不能保证保留。

Files Saved During App Updates

When a user downloads an app update,iTunes installs the update in a new app directory. It then moves theuser’s data files from the old installation over to the new appdirectory before deleting the old installation. Files in the followingdirectories are guaranteed to be preserved during the update process:

  • Application_Home/Documents
  • Application_Home/Library

Although filesin other user directories may also be moved over, you should not relyon them being present after an update.

https://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/PerformanceTuning/PerformanceTuning.html

如果您已经在用户手机上部署了该应用程序,那么您可以做的是当您从 sqlite 读取 url 时,删除前导路径(例如:/var/mobile/Applications/---guid---/文档),然后在使用前重新保存该条目。

关于ios - 更新应用程序时,iPhone 中的所有本地文件都会被删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17546475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com