应用程序在 iOS10 崩溃,出现异常 "There doesn't seem to be a valid compiled storyboard at path"

App crashes on iOS10 with exception "There doesn't seem to be a valid compiled storyboard at path"

自 iOS10 起,我有用户抱怨我的应用程序不断随机崩溃,尤其是在屏幕锁定时。当他们解锁屏幕时,他们可以看到该应用程序一秒钟,然后它崩溃了。在日志中我可以看到很多这样的条目:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'There doesn't seem to be a valid compiled storyboard at path '/var/containers/Bundle/Application/serialcode/XXX.app/AppLaunchStoryboard.storyboardc'' *** First throw call stack: (0x1d465e07 0x1c6cb077 0x22c14083 0xe7d55 0x115ae7 0xbe37d 0x2252897f 0x22726e9d 0x1ed151e1 0x1dd46419 0x1dcc5743 0x1ec98f3f 0x1ed0f3d1 0x1ed1503d 0x227276fd 0x227273c1 0x22a2fa07 0x1ecfef2d 0x1ed2a9cb 0x1ed2a885 0x1ed2ab6f 0x1d421c8b 0x1d421795 0x1d41fa6b 0x1d36f073 0x1d36ee81 0x1eb17bfd 0x2250fccf 0x2250a401 0xbf879 0x1cb3a50b) libc++abi.dylib: terminating with uncaught exception of type NSException

"invalid" 文件通常是 AppLaunchStoryboard.storyboard 尽管我也看到了对其他故事板文件和 .xib 文件的引用。

谷歌搜索上述错误指向 XCode 中与 iOS 架构相关的错误构建设置,我已经仔细检查过。如果我的应用程序不是为正确的架构构建的,那么该应用程序肯定甚至无法首先 运行?

此问题无法可靠地重现,随时可能发生。

如有任何建议,我们将不胜感激。

此问题已通过在 NSFetchedResultsControllers 中禁用缓存得到解决。

之前没有提到的一些症状,因为我不知道这些症状是相关的:

  • 我无法在调试环境中重现崩溃,只能在 Beta 或 Release 版本中重现。
  • 错误信息:

    [error] error: (NSFetchedResultsController): couldn't read cache file to update store info timestamps

    经常记录在调试输出中,但从未记录在生产日志中。

  • 仔细观察上面的错误信息后,我发现我的应用程序正在创建大量的文件描述符,在缓存文件夹中打开文件并且从未关闭或释放它们。

我的应用程序有相当多的 NSFetchedResultsControllers 创建于:

NSFetchedResultsController *fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:context sectionNameKeyPath:nil cacheName:@"someName"];

我改成了:

NSFetchedResultsController *fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:context sectionNameKeyPath:nil cacheName:nil];

解决了问题。

以下 post 也帮助我指明了正确的方向: too-many-open-files-after-calling-fabric-framework-run