仅针对临时构建和旧设备保存时核心数据崩溃

Posted

技术标签:

【中文标题】仅针对临时构建和旧设备保存时核心数据崩溃【英文标题】:Core data crash on save for ad hoc build and older devices only 【发布时间】:2016-12-02 17:41:08 【问题描述】:

我在我们的应用程序中使用 CoreData 已经有一段时间了,到目前为止一切都很好,直到我将我们的最新版本分发给其他团队成员,其中一位成员无法在她的手机上加载应用程序 (4s) ,它只是崩溃了。我追查了一下,发现在ManagedObjectContext上调用save()有问题,我还是不知道为什么;需要明确的是,当我直接构建到任何设备时,它都能完美运行,但 4s 和 5(适用于 5s)在临时安装时都会崩溃。

所有经过测试的设备都没有安装应用程序,所以它似乎不是迁移问题(我设置了一个轻量级迁移以防万一)。

这里是崩溃日志,任何帮助都会很棒。

Incident Identifier: 3E7C526F-7210-4F88-B298-C83D665C066B
CrashReporter Key:   78c1b7a7751600091f9b4b7909eec333e0f5779a
Hardware Model:      iPhone5,2
Process:             APP [401]
Path:                /private/var/containers/Bundle/Application/004CE56E-AFF8-4BF0-8861-E7617F4635B6/APP.app/APP
Identifier:          com.app.APP
Version:             1.7 (1.8)
Code Type:           ARM (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           com.app. [551]


Date/Time:           2016-12-02 17:27:32.1384 +0000
Launch Time:         2016-12-02 17:27:28.0000 +0000
OS Version:          iPhone OS 10.1.1 (14B100)
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_PROTECTION_FAILURE at 0x006e6000
Triggered by Thread:  0

Filtered syslog:
None found

Thread 0 name:  Dispatch queue: SQLQueue 0x1466e820 for APP.sqlite
Thread 0 Crashed:
0   libsystem_platform.dylib        0x1b0b01ba 0x1b0af000 + 4538
1   libswiftCore.dylib              0x0109d3c4 0xf36000 + 1471428
2   libswiftCore.dylib              0x0105ea58 0xf36000 + 1215064
3   libswiftCore.dylib              0x00fbd67c 0xf36000 + 554620
4   libswiftCore.dylib              0x00fcc3bc 0xf36000 + 615356
5   libswiftCore.dylib              0x00fcc208 0xf36000 + 614920
6   libswiftCore.dylib              0x00fcd540 0xf36000 + 619840
7   CoreFoundation                  0x1b7a888e 0x1b759000 + 325774
8   Foundation                      0x1c0efee2 0x1c08b000 + 413410
9   Foundation                      0x1c0ef0b0 0x1c08b000 + 409776
10  Foundation                      0x1c0f029c 0x1c08b000 + 414364
11  Foundation                      0x1c0ef0b0 0x1c08b000 + 409776
12  Foundation                      0x1c0f54ee 0x1c08b000 + 435438
13  CoreData                        0x1d7b7bfe 0x1d7a2000 + 89086
14  CoreData                        0x1d7edaa4 0x1d7a2000 + 309924
15  CoreData                        0x1d983498 0x1d7a2000 + 1971352
16  CoreData                        0x1d984d46 0x1d7a2000 + 1977670
17  CoreData                        0x1d979c34 0x1d7a2000 + 1932340
18  CoreData                        0x1d886984 0x1d7a2000 + 936324
19  libdispatch.dylib               0x1af01082 0x1af00000 + 4226
20  libdispatch.dylib               0x1af0d3a2 0x1af00000 + 54178
21  CoreData                        0x1d8867bc 0x1d7a2000 + 935868
22  CoreData                        0x1d9545aa 0x1d7a2000 + 1779114
23  CoreData                        0x1d8b6fbe 0x1d7a2000 + 1134526
24  CoreData                        0x1d8b0a5a 0x1d7a2000 + 1108570
25  CoreData                        0x1d7be12c 0x1d7a2000 + 114988
26  CoreData                        0x1d89334e 0x1d7a2000 + 987982
27  CoreData                        0x1d88b806 0x1d7a2000 + 956422
28  CoreData                        0x1d7bdc4e 0x1d7a2000 + 113742
29  CoreData                        0x1d7dd3f8 0x1d7a2000 + 242680
30  APP                             0x000bdbbc 0x70000 + 318396
31  APP                             0x000bee4c 0x70000 + 323148
32  APP                             0x000bea9c 0x70000 + 322204
33  APP                             0x00146c90 0x70000 + 879760
34  APP                             0x001458dc 0x70000 + 874716
35  APP                             0x00146bb0 0x70000 + 879536
36  libdispatch.dylib               0x1af01096 0x1af00000 + 4246
37  libdispatch.dylib               0x1af01082 0x1af00000 + 4226
38  libdispatch.dylib               0x1af055fc 0x1af00000 + 22012
39  CoreFoundation                  0x1b816a16 0x1b759000 + 776726
40  CoreFoundation                  0x1b814cfe 0x1b759000 + 769278
41  CoreFoundation                  0x1b764072 0x1b759000 + 45170
42  CoreFoundation                  0x1b763e80 0x1b759000 + 44672
43  GraphicsServices                0x1cf10bfc 0x1cf07000 + 39932
44  UIKit                           0x2091e82e 0x208a4000 + 501806
45  UIKit                           0x20918f60 0x208a4000 + 479072
46  APP                         0x00095388 0x70000 + 152456
47  libdyld.dylib                   0x1af2e50a 0x1af2b000 + 13578

Thread 1:
0   libsystem_pthread.dylib         0x1b0b6484 0x1b0b5000 + 5252

Thread 2:
0   libsystem_pthread.dylib         0x1b0b6484 0x1b0b5000 + 5252

Thread 3:
0   libsystem_pthread.dylib         0x1b0b6484 0x1b0b5000 + 5252

Thread 4:
0   libsystem_kernel.dylib          0x1b004744 0x1afed000 + 96068
1   libsystem_pthread.dylib         0x1b0b69a0 0x1b0b5000 + 6560
2   libsystem_pthread.dylib         0x1b0b648c 0x1b0b5000 + 5260

Thread 5 name:  com.apple.uikit.eventfetch-thread
Thread 5:
0   libsystem_kernel.dylib          0x1afee83c 0x1afed000 + 6204
1   libsystem_kernel.dylib          0x1afee62e 0x1afed000 + 5678
2   CoreFoundation                  0x1b816868 0x1b759000 + 776296
3   CoreFoundation                  0x1b814b66 0x1b759000 + 768870
4   CoreFoundation                  0x1b764072 0x1b759000 + 45170
5   CoreFoundation                  0x1b763e80 0x1b759000 + 44672
6   Foundation                      0x1c0960da 0x1c08b000 + 45274
7   Foundation                      0x1c0b4df0 0x1c08b000 + 171504
8   UIKit                           0x21226cb2 0x208a4000 + 9972914
9   Foundation                      0x1c17f0d0 0x1c08b000 + 999632
10  libsystem_pthread.dylib         0x1b0b8a16 0x1b0b5000 + 14870
11  libsystem_pthread.dylib         0x1b0b893c 0x1b0b5000 + 14652
12  libsystem_pthread.dylib         0x1b0b6498 0x1b0b5000 + 5272

Thread 6 name:  com.apple.NSURLConnectionLoader
Thread 6:
0   libsystem_kernel.dylib          0x1afee83c 0x1afed000 + 6204
1   libsystem_kernel.dylib          0x1afee62e 0x1afed000 + 5678
2   CoreFoundation                  0x1b816868 0x1b759000 + 776296
3   CoreFoundation                  0x1b814b66 0x1b759000 + 768870
4   CoreFoundation                  0x1b764072 0x1b759000 + 45170
5   CoreFoundation                  0x1b763e80 0x1b759000 + 44672
6   CFNetwork                       0x1be2edb8 0x1bd83000 + 703928
7   Foundation                      0x1c17f0d0 0x1c08b000 + 999632
8   libsystem_pthread.dylib         0x1b0b8a16 0x1b0b5000 + 14870
9   libsystem_pthread.dylib         0x1b0b893c 0x1b0b5000 + 14652
10  libsystem_pthread.dylib         0x1b0b6498 0x1b0b5000 + 5272

Thread 7 name:  com.twitter.crashlytics.ios.MachExceptionServer
Thread 7:
0   libsystem_kernel.dylib          0x1afee83c 0x1afed000 + 6204
1   libsystem_kernel.dylib          0x1afee62e 0x1afed000 + 5678
2   APP                             0x00408b9a 0x70000 + 3771290
3   libsystem_pthread.dylib         0x1b0b8a16 0x1b0b5000 + 14870
4   libsystem_pthread.dylib         0x1b0b893c 0x1b0b5000 + 14652
5   libsystem_pthread.dylib         0x1b0b6498 0x1b0b5000 + 5272

Thread 8:
0   libsystem_kernel.dylib          0x1b004744 0x1afed000 + 96068
1   libsystem_pthread.dylib         0x1b0b69a0 0x1b0b5000 + 6560
2   libsystem_pthread.dylib         0x1b0b648c 0x1b0b5000 + 5260

Thread 9:
0   libsystem_kernel.dylib          0x1b004744 0x1afed000 + 96068
1   libsystem_pthread.dylib         0x1b0b69a0 0x1b0b5000 + 6560
2   libsystem_pthread.dylib         0x1b0b648c 0x1b0b5000 + 5260

Thread 10 name:  Dispatch queue: com.apple.network.connections
Thread 10:
0   libcorecrypto.dylib             0x1aecdbe8 0x1aea7000 + 158696
1   libsystem_coretls.dylib         0x1afc7622 0x1afb9000 + 58914
2   libsystem_coretls.dylib         0x1afc5a14 0x1afb9000 + 51732
3   libsystem_coretls.dylib         0x1afc619a 0x1afb9000 + 53658
4   libnetwork.dylib                0x26824048 0x267dd000 + 290888
5   libnetwork.dylib                0x26826138 0x267dd000 + 299320
6   libnetwork.dylib                0x26802992 0x267dd000 + 154002
7   libdispatch.dylib               0x1af0cb9a 0x1af00000 + 52122
8   libdispatch.dylib               0x1af17a84 0x1af00000 + 96900
9   libdispatch.dylib               0x1af02cb4 0x1af00000 + 11444
10  libdispatch.dylib               0x1af0dd2c 0x1af00000 + 56620
11  libdispatch.dylib               0x1af04378 0x1af00000 + 17272
12  libdispatch.dylib               0x1af0eb9c 0x1af00000 + 60316
13  libdispatch.dylib               0x1af1488e 0x1af00000 + 84110
14  libsystem_pthread.dylib         0x1b0b67f0 0x1b0b5000 + 6128
15  libsystem_pthread.dylib         0x1b0b648c 0x1b0b5000 + 5260

Thread 11:
0   libsystem_pthread.dylib         0x1b0b6484 0x1b0b5000 + 5252

Thread 12:
0   libsystem_kernel.dylib          0x1b004744 0x1afed000 + 96068
1   libsystem_pthread.dylib         0x1b0b69a0 0x1b0b5000 + 6560
2   libsystem_pthread.dylib         0x1b0b648c 0x1b0b5000 + 5260

Thread 0 crashed with ARM Thread State (32-bit):
    r0: 0x006e6000    r1: 0x006e6000      r2: 0x0029267c      r3: 0x00000000
    r4: 0x00000000    r5: 0x00000000      r6: 0x14586ae0      r7: 0x007e3350
    r8: 0x007e33c8    r9: 0x004bc340     r10: 0x007e33d4     r11: 0x0118efdc
    ip: 0x00000000    sp: 0x007e3350      lr: 0x0109d3c4      pc: 0x1b0b01ba
  cpsr: 0x20000030

【问题讨论】:

我很好奇你知道崩溃线程名称的意义吗?为什么是“调度队列:SQLQueue”而不是主队列,但它似乎包含应用程序启动的完整堆栈?我实际上有一个类似的堆栈跟踪。 【参考方案1】:

崩溃日志中没有太多有用的细节。但是,鉴于这只是旧设备上的问题,我会调查两个方面。您需要一个遭受此崩溃影响的测试设备。

    内存。较旧的设备具有较少的内容,如果您积累了大量未保存的更改,您可能会用完。具有更多内存的设备不太可能出现问题。您可以使用 Xcode 的内存监控快速检查这一点——如果您在保存时看到内存峰值,您知道您需要通过 Instruments 更仔细地查看。

    速度,如果您在主线程上保存。如果你阻塞主线程太久,iOS 可能会判断你的应用程序已经停止响应并杀死它。同样,较慢的设备可能会出现问题,而较新的设备则可以。请记住,通过 Xcode 调试时可能不会发生这种崩溃,因为它会影响 iOS 决定终止应用程序的时间。

其中的每一个都可能伴随着设备控制台中的有用消息,这些消息可能只是告诉您问题所在。您可以使用 Xcode 或使用 free iOS Console app 获取这些。

【讨论】:

谢谢汤姆,我尝试了您建议的工具并设法获得了更多的洞察力,但目前还没有更接近解决方案。

以上是关于仅针对临时构建和旧设备保存时核心数据崩溃的主要内容,如果未能解决你的问题,请参考以下文章

使用临时分发的设备崩溃

当 cached_network_image 或 Image.Network 填充数据时,Flutter 应用程序崩溃很多,仅显示与设备的连接丢失而已

从文件路径获取数据时崩溃

设备和模拟器上的调试工作时,临时 iPhone SIGSEGV 崩溃

iOS设备空闲时奇怪的崩溃?

如何在科尔多瓦 Android 应用程序中仅定位平板设备