• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 应用更新后 CoreData 崩溃

[复制链接]
菜鸟教程小白 发表于 2022-12-12 14:19:14 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我有一个非常烦人的问题。我有一个“CoreData”应用程序,目前正在生产中,一切正常。我有应用程序的更新,但只要在原始应用程序上安装更新程序,应用程序就会在下面的代码行中崩溃。

[_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL optionsptions error:&error]

我收到的错误是“Can't use fetch request with fetched property description (entity model mismatch)”。

CoreData 模型发生了更改,但我为我的更改创建了一个新版本的模型,因此它应该将更改合并到新模型中。这是我已经做了一百次的相同过程,并且始终有效。这次除外。

我能想到的唯一可能导致此问题的区别是,我从 CoreData 模型中删除了一些旧的 Fetch Requests,但这是在更新的模型版本中完成的,而不是在原始模型中完成的。

你们都知道是什么原因造成的吗?正如我所提到的,我确实更新了 CoreData 模型版本并将其选为应用程序的当前模型。此外,非常奇怪的是,只有在更新后第一次运行应用程序时才会发生崩溃。崩溃发生后,我可以重新启动应用程序,一切正常。

谢谢!

!** 编辑**!

如果这有帮助,这里是我的调用堆栈。

Last Exception Backtrace:
0   CoreFoundation                  0x32ac029e __exceptionPreprocess + 158
1   libobjc.A.dylib                 0x3a95697a objc_exception_throw + 26
2   CoreFoundation                  0x32ac01c0 +[NSException raise:format:] + 100
3   CoreData                        0x328a2678 -[NSFetchedPropertyDescription setFetchRequest:] + 164
4   CoreData                        0x328a2788 -[NSFetchedPropertyDescription _createCachesAndOptimizeState] + 76
5   CoreData                        0x32899b0a -[NSEntityDescription(_NSInternalMethods) _createCachesAndOptimizeState] + 1238
6   CoreData                        0x328d18a6 -[NSManagedObjectModel(_NSInternalMethods) _createCachesAndOptimizeState] + 702
7   CoreData                        0x3284e534 -[NSManagedObjectModel(_NSInternalMethods) _setIsEditableptimizationStyle:] + 272
8   CoreData                        0x3284e2f2 -[NSPersistentStoreCoordinator initWithManagedObjectModel:] + 302
9   CoreData                        0x32939c4c -[NSSQLiteInPlaceMigrationManager migrateStoreFromURL:typeptions:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:] + 692
10  CoreData                        0x328da838 -[NSMigrationManager migrateStoreFromURL:typeptions:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:] + 512
11  CoreData                        0x3292bc54 -[NSStoreMigrationPolicy(InternalMethods) migrateStoreAtURL:toURL:storeTypeptions:withManager:error:] + 276
12  CoreData                        0x3292afa8 -[NSStoreMigrationPolicy migrateStoreAtURL:withManager:metadataptions:error:] + 84
13  CoreData                        0x3292c4b2 -[NSStoreMigrationPolicy(InternalMethods) _gatherDataAndPerformMigration:] + 1930
14  CoreData                        0x3284f384 -[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URLptions:error:] + 3340
15  MSM iPad                        0x001cb4c2 -[VS_CoreDataManager persistentStoreCoordinator] + 466
16  MSM iPad                        0x001cbb12 -[VS_CoreDataManager initializeCoreDataWithProjectName:] + 94
17  MSM iPad                        0x000b6678 -[AppDelegate application:didFinishLaunchingWithOptions:] (AppDelegate.m:117)
18  UIKit                           0x34928ad4 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 248
19  UIKit                           0x3492865e -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1186
20  UIKit                           0x34920846 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 694
21  UIKit                           0x348c8c34 -[UIApplication handleEvent:withNewEvent:] + 1000
22  UIKit                           0x348c86c8 -[UIApplication sendEvent:] + 68
23  UIKit                           0x348c8116 _UIApplicationHandleEvent + 6150
24  GraphicsServices                0x365bc59e _PurpleEventCallback + 586
25  GraphicsServices                0x365bc1ce PurpleEventCallback + 30
26  CoreFoundation                  0x32a9516e __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 30
27  CoreFoundation                  0x32a95112 __CFRunLoopDoSource1 + 134
28  CoreFoundation                  0x32a93f94 __CFRunLoopRun + 1380
29  CoreFoundation                  0x32a06eb8 CFRunLoopRunSpecific + 352
30  CoreFoundation                  0x32a06d44 CFRunLoopRunInMode + 100
31  UIKit                           0x3491f480 -[UIApplication _run] + 664
32  UIKit                           0x3491c2fc UIApplicationMain + 1116
33  MSM iPad                        0x000b6432 main (main.m:17)
34  libdyld.dylib                   0x3ad8db1c start + 0



Best Answer-推荐答案


我发现我必须在应用更新后删除缓存:

要么不缓存获取的项目

 NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];

或在更新时删除缓存

[NSFetchedResultsController deleteCacheWithName"Master"];

关于ios - 应用更新后 CoreData 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18622056/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap