2017-03-07 165 views
0

我們已將應用更新爲新版本。Swift:在applicationWillTerminate後獲取persistentStoreCoordinator時核心數據崩潰

有一個新功能添加到新版本,我們爲該功能添加了一個新的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 
+0

在Core Data中添加新字段,實體會使您以前的Core數據模型無效,從而導致崩潰。如果你刪除應用程序並重新安裝它應該工作。 –

+0

該堆棧跟蹤顯示應用程序在嘗試保存更改時崩潰。沒有其他有用的信息。這是您嘗試保存更改的唯一時間嗎?如果你在其他時間保存,會發生什麼?除了堆棧跟蹤之外,還有哪些錯誤消息? –

回答

0

首先,您應該發佈惡意代碼,例如, AppDelegate中的getters(行號參見堆棧跟蹤)。

一般來說,等到應用程序終止時可能需要很長時間(因爲iOS會讓iOS 4保持活躍狀態​​,我認爲)。你可以將邏輯轉換爲applicationDidEnterBackground,但我認爲這也是容易出錯的,因爲如果應用程序崩潰,就不會調用它。

您應該儘可能經常保存上下文(但不是更常見:-),例如:每次視圖控制器被解僱或者等等。