【问题标题】:App Store upgrade install deleting filesApp Store升级安装删除文件
【发布时间】:2014-12-09 20:24:46
【问题描述】:

堆栈溢出:

我需要帮助。我在应用商店中有一个应用,它收集用户输入(文本)并将其保存到应用沙箱的 Documents 文件夹中的存档文件(NSKeyedArchiver)中。数据在通过 NSKeyedUnarchiver 启动时进行翻新。此过程在多次更新中运行良好。我刚刚向 iTunes Store 发布了应用程序的更新,有人声称他们的数据已丢失。我的问题是我无法重现失败。

我现在拥有 iPhone 和 iPad 版本的应用程序,在 iPhone 版本中,我将旧文件名重命名为 iPad 使用的相同名称;这是在 didFinishLaunchingWithOptions 中完成的:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    . . .
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    // get full path to Document subdirectory
    NSString *documentFolder = [paths objectAtIndex:0];

    // form full path for both old and new archive filenames
    self.archiveFile = [documentFolder stringByAppendingPathComponent:oldArchiveName];
    NSString *newArchive = [documentFolder stringByAppendingPathComponent:newArchiveName];
    NSLog(#” *** self.archiveFile (%@)”,self.archiveFile);
    NSLog(#” *** newArchive (%@)”,newArchive);

    // let’s rename the archive
    NSFileManager *fm = [NSFileManager defaultManager];
    // if the old archive filename exists change it to the new name
    if([fm fileExistsAtPath:self.archiveFile])
        (void)[fm moveItemAtPath:self.archiveFile toPath:newArchive error:nil];

    // self.archiveFile now points to the new archive file
    self.archiveFile = newArchive;
    NSLog(#” *** self.archiveFile (%@)”,self.archiveFile);
    . . .
}

从 Xcode 设备窗口的控制台子窗口:

10 月 14 日 14:02:46 Randy-Merritts-iPad phoneFilebox[11096]: *** self.archiveFile (/var/mobile/Containers/Data/Application/3BF0757B-96F4-4AAA-9CEB-6C87505CA6BD/Documents/cabself.xobeliF)

10 月 14 日 14:02:46 Randy-Merritts-iPad phoneFilebox[11096]: *** newArchive (/var/mobile/Containers/Data/Application/3BF0757B-96F4-4AAA-9CEB-6C87505CA6BD/Documents/iFilebox.cabinet)

10 月 14 日 14:02:46 Randy-Merritts-iPad phoneFilebox[11096]: *** self.archiveFile (/var/mobile/Containers/Data/Application/3BF0757B-96F4-4AAA-9CEB-6C87505CA6BD/Documents/iFilebox.cabinet)

来自我的用户的投诉表明该应用尝试打开“self.archiveFile”失败(如果在文档中未找到存档,则表示您是新用户,我创建了一个空存档准备接收新数据)。问题是:它对我来说永远不会失败。此外,安装新更新后,您可以输入新数据、终止应用程序、重新启动应用程序,所有(新)数据都在那里。如果我解压数据的方式存在编程缺陷,这种失败不会重复吗?

我使用 Xcode 6.0.1 设备窗口安装新版本以及 www.diawi.com 将测试版本分发给团队成员,我们都没有丢失任何数据;注意这两种方法严格执行更新;他们不会(也没有任何理由)干扰 Documents 子目录。

但是,我们可以通过从 App Store 下载副本来重现数据丢失问题。 App Store 下载/设备内应用更新过程似乎正在重置 Document 文件夹并删除任何以前的文件。

有人看过吗?有人知道这个问题吗?为什么要从 App Store 安装升级版

【问题讨论】:

  • 还有一项。我需要在 plist 文件中设置什么吗?权利文件?分布概况?我应该包括任何其他文件吗?

标签: iphone installation store


【解决方案1】:

我最近在进行应用升级时遇到了类似的问题。 我将 .epub 和 .pdf 文件保存在 Documents 文件夹中。 用户报告说,升级后应用程序找不到这些。 在我看来,这些文件要么在升级过程中被删除,要么由于任何原因应用程序无法访问它们。

我无法重现该问题。 我通常使用 Testflight 从 Xcode 分发或安装。 用户在 ios7 和 ios8 设备上都报告了该问题。

我还没有找到原因,但这是我遵循的线索:

  1. 通过绝对路径访问 Documents 文件夹 对我来说不是这样,如果是这样,它也应该发生在 Testflight 升级中。 查看相关:First App Update, User Data Lost (was stored in Documents directory)

  2. 更改应用程序的开发团队。 对我来说就是这种情况,因为我之前已将应用程序从一个开发者帐户转移到另一个帐户。 但据我所知,iOS 无论如何都应该将旧 Documents 文件夹的内容移动到新文件夹 请参阅相关的跨更新管理数据部分:https://developer.apple.com/library/ios/technotes/tn2285/_index.html

  3. 文件的 NSURLIsExcludedFromBackupKey 使用不正确。 我将其设置为是。 这篇iOS App update new version delete files from Documents folder 的帖子似乎暗示以这种方式标记的文件在升级时可能不会被复制 请参阅“如果您将文件标记为从备份中排除,那么这意味着该文件可以轻松替换。当您安装应用更新时,这些文件不会复制到更新后的应用中” 在任何 Apple 文档中都没有找到任何对此的确认

  4. 也与 NSURLIsExcludedFromBackupKey 设置有关。 如果 iCloud 已激活并且此设置设置为否,则此文件可能会通过 iCould 删除。 请参阅 ios8 iCloud 问题http://www.macrumors.com/2014/09/29/reset-all-settings-icloud-drive-bug/ 我也不是这种情况,因为用户在 ios7 上报告了问题。

以上任何内容对您的实施来说是否熟悉?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-19
    • 2019-02-06
    • 2011-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多