我从XCode获取这些崩溃报告(我在底部粘贴了一个),我无法重现错误或找出问题所在。
从回溯中我认为它可能与decodeObject
内容相关......我确实遇到了新的decodeBool
和decodeDouble
函数的问题,所以要确定我做了一个NSCoder扩展:
func safeDecodeDouble(key: String) -> Double? {
if self.containsValue(forKey: key) {
if let value = self.decodeObject(forKey: key) as? Double {
return value
}
return self.decodeDouble(forKey: key)
}
return nil
}
func safeDecodeBool(key: String) -> Bool? {
if self.containsValue(forKey: key) {
if let value = self.decodeObject(forKey: key) as? Bool {
return value
}
return self.decodeBool(forKey: key)
}
return nil
}
func safeDecodeDate(key: String) -> Date? {
if self.containsValue(forKey: key) {
if let value = self.decodeObject(forKey: key) as? Date {
return value
}
}
return nil
}
func safeDecodeString(key: String) -> String? {
if self.containsValue(forKey: key) {
if let value = self.decodeObject(forKey: key) as? String {
return value
}
}
return nil
}
现在我只在代码中使用safeDecode
函数,但我仍然会收到相同的崩溃报告。
回溯中的第三项说[UIStoryboard storyboardWithName:bundle:]
,但我不知道这与任何事情有什么关系。此外,每个崩溃报告都有关于状态恢复和decodeObject
的内容,因此我认为问题本身并不是故事板实例化。
与此同时,当我在模拟器或设备上测试状态恢复时,我从未遇到任何问题,所以显然它只发生在一些人身上。
关于可能会发生什么的任何想法?
Last Exception Backtrace:
0 CoreFoundation 0x18a146fd8 __exceptionPreprocess + 124 (NSException.m:165)
1 libobjc.A.dylib 0x188ba8538 objc_exception_throw + 56 (objc-exception.mm:521)
2 UIKit 0x190a36850 +[UIStoryboard storyboardWithName:bundle:] + 776 (UIStoryboard.m:99)
3 UIKit 0x190bfacfc -[_UIStoryboardProxy initWithCoder:] + 192 (UIStateRestorationSupport.m:324)
4 Foundation 0x18ab96420 _decodeObjectBinary + 2076 (NSKeyedArchiver.m:2304)
5 Foundation 0x18ab95b58 _decodeObject + 308 (NSKeyedArchiver.m:2467)
6 UIKit 0x1903e62ec -[UIStateRestorationKeyedUnarchiver decodeObjectForKey:] + 88 (UIStateRestorationSupport.m:454)
7 UIKit 0x1903e5ba8 -[UIApplication(StateRestoration) _restoreApplicationPreservationStateWithSessionIdentifier:beginHandler:completionHandler:] + 4772 (UIApplication.m:13551)
8 UIKit 0x1902e76b4 -[UIApplication(StateRestoration) _doRestorationIfNecessary] + 244 (UIApplication.m:13979)
9 UIKit 0x1902e7288 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 296 (UIApplication.m:1792)
10 UIKit 0x1904f3800 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3452 (UIApplication.m:2129)
11 UIKit 0x1904f92a8 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1684 (UIApplication.m:3625)
12 UIKit 0x19050dde0 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke.3151 + 48 (UIApplication.m:10365)
13 UIKit 0x1904f653c -[UIApplication workspaceDidEndTransaction:] + 168 (UIApplication.m:2990)
14 FrontBoardServices 0x18bcef884 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36 (FBSSerialQueue.m:158)
15 FrontBoardServices 0x18bcef6f0 -[FBSSerialQueue _performNext] + 176 (FBSSerialQueue.m:177)
16 FrontBoardServices 0x18bcefaa0 -[FBSSerialQueue _performNextFromRunLoopSource] + 56 (FBSSerialQueue.m:206)
17 CoreFoundation 0x18a0f5424 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24 (CFRunLoop.c:1943)
18 CoreFoundation 0x18a0f4d94 __CFRunLoopDoSources0 + 540 (CFRunLoop.c:1989)
19 CoreFoundation 0x18a0f29a0 __CFRunLoopRun + 744 (CFRunLoop.c:2821)
20 CoreFoundation 0x18a022d94 CFRunLoopRunSpecific + 424 (CFRunLoop.c:3113)
21 UIKit 0x1902e045c -[UIApplication _run] + 652 (UIApplication.m:2658)
22 UIKit 0x1902db130 UIApplicationMain + 208 (UIApplication.m:4089)
23 Leio 0x1000b6ecc main + 120 (BookInfoTableViewController.swift:19)
24 libdyld.dylib 0x18903159c start + 4
编辑:这里出现了一个不同的崩溃报告,并显示状态恢复确实存在问题。不过,我自己永远无法重现它。 :/
0 CoreFoundation 0x18385adb0 __exceptionPreprocess + 124 (NSException.m:162)
1 libobjc.A.dylib 0x182ebff80 objc_exception_throw + 56 (objc-exception.mm:531)
2 Foundation 0x1841d4704 -[NSCoder(Exceptions) __failWithException:] + 132 (NSCoder.m:544)
3 Foundation 0x1841d48bc -[NSCoder(Exceptions) __failWithExceptionName:errorCode:format:] + 440 (NSCoder.m:580)
4 Foundation 0x1841a33b8 _decodeObjectBinary + 2996 (NSKeyedArchiver.m:2173)
5 Foundation 0x1841a274c _decodeObject + 304 (NSKeyedArchiver.m:2313)
6 UIKit 0x188b3e20c -[UIStateRestorationKeyedUnarchiver decodeObjectForKey:] + 88 (UIStateRestorationSupport.m:454)
7 UIKit 0x188b3daf8 -[UIApplication(StateRestoration) _restoreApplicationPreservationStateWithSessionIdentifier:beginHandler:completionHandler:] + 4908 (UIApplication.m:15043)
8 UIKit 0x188a32d44 -[UIApplication(StateRestoration) _doRestorationIfNecessary] + 244 (UIApplication.m:15471)
9 UIKit 0x188a32964 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 308 (UIApplication.m:1860)
10 UIKit 0x188c62184 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2904 (UIApplication.m:2112)
11 UIKit 0x188c665f0 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1684 (UIApplication.m:3355)
12 UIKit 0x188c63764 -[UIApplication workspaceDidEndTransaction:] + 168 (UIApplication.m:2748)
13 FrontBoardServices 0x1851fb7ac __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36 (FBSSerialQueue.m:158)
14 FrontBoardServices 0x1851fb618 -[FBSSerialQueue _performNext] + 168 (FBSSerialQueue.m:177)
15 FrontBoardServices 0x1851fb9c8 -[FBSSerialQueue _performNextFromRunLoopSource] + 56 (FBSSerialQueue.m:206)
16 CoreFoundation 0x18381109c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24 (CFRunLoop.c:1761)
17 CoreFoundation 0x183810b30 __CFRunLoopDoSources0 + 540 (CFRunLoop.c:1807)
18 CoreFoundation 0x18380e830 __CFRunLoopRun + 724 (CFRunLoop.c:2536)
19 CoreFoundation 0x183738c50 CFRunLoopRunSpecific + 384 (CFRunLoop.c:2814)
20 UIKit 0x188a2b94c -[UIApplication _run] + 460 (UIApplication.m:2578)
21 UIKit 0x188a26088 UIApplicationMain + 204 (UIApplication.m:3772)
22 Leio 0x1000f6ecc main + 120 (BookInfoTableViewController.swift:19)
23 libdyld.dylib 0x1832d68b8 start + 4 (start_glue.s:78)