【问题标题】:Swift : core data crashed when getting persistentStoreCoordinator after applicationWillTerminateSwift:在 applicationWillTerminate 之后获取 persistentStoreCoordinator 时核心数据崩溃
【发布时间】:2017-03-07 05:13:05
【问题描述】:

我们将应用更新到了新版本。

新版本中添加了一个新函数,我们为该函数添加了一个新的 coredata 表。

应用程序发布后,错误继续没有答案。 有人会遇到同样的错误或同样的问题并解决这个错误吗?

Thread 0 Crashed:
0   libsystem_kernel.dylib              0x000000018981f014 __pthread_kill + 8
1   libsystem_c.dylib                   0x0000000189793400 abort + 140
2   [AppName]                           0x00000001002d0c58 AppDelegate.(persistentStoreCoordinator.getter).(closure #1) (AppDelegate.swift:318)
3   [AppName]                           0x00000001002c7dec AppDelegate.persistentStoreCoordinator.getter (AppDelegate.swift:334)
4   [AppName]                           0x00000001002d0cbc AppDelegate.(managedObjectContext.getter).(closure #1) (AppDelegate.swift:338)
5   [AppName]                           0x00000001002c8054 AppDelegate.managedObjectContext.getter (AppDelegate.swift:342)
6   [AppName]                           0x00000001002c8198 AppDelegate.saveContext() (AppDelegate.swift:347)
7   [AppName]                           0x00000001002c7780 AppDelegate.applicationWillTerminate() (AppDelegate.swift:295)
8   [AppName]                           0x00000001002c77d8 @objc AppDelegate.applicationWillTerminate() (AppDelegate.swift:0)
9   UIKit                               0x0000000190792704 <redacted> + 244
10  UIKit                               0x00000001909947cc <redacted> + 792
11  UIKit                               0x0000000190997fdc <redacted> + 292
12  UIKit                               0x0000000190989d50 <redacted> + 560
13  UIKit                               0x00000001906f90b4 <redacted> + 168
14  CoreFoundation                      0x000000018a7fe0c0 <redacted> + 32
15  CoreFoundation                      0x000000018a7fbcf0 <redacted> + 372
16  CoreFoundation                      0x000000018a7fc180 <redacted> + 1024
17  CoreFoundation                      0x000000018a72a2b8 CFRunLoopRunSpecific + 444
18  GraphicsServices                    0x000000018c1de198 GSEventRunModal + 180
19  UIKit                               0x00000001907717fc <redacted> + 684
20  UIKit                               0x000000019076c534 UIApplicationMain + 208
21  [AppName]                           0x00000001002d1a94 main (AppDelegate.swift:17)
22  ???                                 0x000000018970d5b8 0x0 + 0

【问题讨论】:

  • 添加新字段,Core Data 中的实体会使您之前的 Core 数据模型失效,这可能会导致崩溃。如果您删除应用程序并重新安装它应该可以工作。
  • 该堆栈跟踪显示应用程序在尝试保存更改时崩溃。没有其他有用的信息。这是您唯一一次尝试保存更改吗?如果您在其他时间保存会发生什么?除了堆栈跟踪之外,您还会收到哪些错误消息?

标签: ios core-data crash


【解决方案1】:

首先,您应该发布错误的代码,例如AppDelegate 中的 getter(行号参见堆栈跟踪)。

一般来说,等到应用程序终止可能需要很长时间(因为 iOS 试图让它们保持活动状态,我认为是 iOS 4)。您可以将逻辑转移到applicationDidEnterBackground,但我认为这也容易出错,因为如果应用程序以某种方式崩溃,它将不会被调用。

您应该尽可能多地保存上下文(但不要更频繁:-),例如每次视图控制器被关闭时。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-28
    • 1970-01-01
    相关资源
    最近更新 更多