将应用程序更新到最新版本后,文件不再可读 [英] Files are no longer readable after updating application to newest version

查看:164
本文介绍了将应用程序更新到最新版本后,文件不再可读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用iPad的企业分布式应用程序大约一年。当时我们已经发布了5个生产版本,从未出现过任何问题。每次我们的用户已经安装了新版本的旧版本,我们的Core Data迁移总是工作正常。 UNTIL我们为应用程序添加了视频录制。

I have been working on an Enterprise distributed application for the iPad for about a year. We have released 5 production builds in that time and never experienced any issues. Every time our users have installed the new build over the old version, and our Core Data migrations always worked fine. UNTIL we added video recording to the application.

我们一直将Media存储在Core Data Externally Managed数据类型中。这是工作正常,直到我们开始允许用户创建大型视频。因此,我们发现Core Data迁移会删除超过〜5mb的任何文件。在这一点上,我们滚动了我们自己的文件管理方案。这完成得很好,我们自己手动迁移的文件从Core Data和我们自己的方案。这是释放没有问题。

We had been storing 'Media' in the Core Data Externally Managed data type. This was working fine until we started to allow the user to create large videos. So we then discovered that Core Data migrations trash any file that is over ~5mb. At this point we rolled our own File Management scheme. This worked out perfectly fine, we wrote our own manual migration of the files out of Core Data and into our own scheme. This was released without issue.

那时,当推出我们的下一个功能,突然一个问题弹出了。从Xcode构建时从未出现任何问题...但是,在使用Enterprise Deployment重新部署后,写入先前构建中的文件系统的任何文件突然无法读取。如果设备插入XCode,则文件在管理器中清晰可见。但是NSFileManager / NSFileHandle / NSData找不到文件。他们总是报告他们经历:

THEN, when it came time to roll out our NEXT set of features, suddenly a problem popped up. There were never any issues when building from Xcode... But, after redeploying using Enterprise Deployment, any of the files that were written to the filesystem in the previous build were suddenly unreadable. If a device is plugged into XCode, the files are clearly visible in the Organizer. However NSFileManager/NSFileHandle/NSData can not find the files. They always report that they experience:

error: {
    NSFilePath = "/var/mobile/Applications/3CFB07B3-D17F-45D7-A233-4E56930D794C/Documents/ep_binary_data/9465C282-7ED2-428E-B7D3-545BCFE4DFC5";
    NSUnderlyingError = "Error Domain=NSPOSIXErrorDomain Code=2 \"The operation couldn\U2019t be completed. No such file or directory\"";
}

像我说的,我可以验证该文件在该路径执行EXIST使用XCode管理器。任何帮助将非常感谢。

Like I said, I can verify that the file DOES ACTUALLY EXIST at that path using the XCode Organizer. Any help would be greatly appreciated. I have been banging my head off the desk all day trying to figure this out.

用于阅读的代码如下:

NSError *err = nil;
NSData *data = [[NSData alloc] initWithContentsOfFile:self.thumbnail_url 
                                              options:NSDataReadingMappedIfSafe 
                                                error:&err];
if (err != nil) logger(@"error: %@",[err userInfo]);

并写下:

NSError *error = nil;
[thumbnail_ep_managed writeToFile:filePath options:NSDataWritingAtomic error:&error];
if(error != nil)
{
    NSLog(@"error writing file to path: %@\nerror: %@",filePath,[[error userInfo]description]);
}

我累死了 b $ b

推荐答案

我在一些Goons at SomethingAwful的帮助下找到了解决方案。问题是我正在存储FULL路径,如包含文档目录。这是iOS设备上的错误。你不能保证在升级后,bundle路径仍然是一样的。

I found the solution with the help of some Goons at SomethingAwful. The issue was that I was storing the FULL path, as in including the documents directory. This is a mistake on an iOS device. You cannot guarantee that after an upgrade, the bundle path will still be the same.

有时在升级应用程序时,会更改作为散列的捆绑标识符(安装应用程序的目录的名称)。因此,如果您存储完整路径,并且升级可能制动存储的路径。解决方案是只保留从文档目录开始的相对路径。

Sometimes the bundle identifier (the name of the directory the app is installed in), which is a hash, is changed when upgrading an application. So if you store the full path, and upgrade may brake the stored paths. The solution is to only persist a relative path, starting from the documents directory.

然后,当您启动应用程序时,缓存documents目录,并追加您的持久相对路径。

Then when you start the application, cache the documents directory, and append your persistent relative paths.

/var/mobile/Applications/3CFB07B3-D17F-45D7-A233-4E56930D794C/Documents/ep_binary_data/9465C282-7ED2-428E-B7D3-545BCFE4DFC5

此部分可以更改:

3CFB07B3-D17F-45D7-A233-4E56930D794C

所以我只应该存储:

ep_binary_data/9465C282-7ED2-428E-B7D3-545BCFE4DFC5

并获取:

/var/mobile/Applications/3CFB07B3-D17F-45D7-A233-4E56930D794C/Documents/

部分在应用程序启动。

Voila,文件保持工作。 :)

Voila, the files keep working. :)

这篇关于将应用程序更新到最新版本后,文件不再可读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆