我遇到了一个问题,我们的用户中有一小部分(几个%)用我的应用程序崩溃,并带有以下跟踪:
Crashed: com.apple.main-thread
0 libswiftCore.dylib 0x100ae3740 _TTSfq4n_s_n_n_n___TFs17_assertionFailureFTVs12StaticStringSS4fileS_4lineSu5flagsVs6UInt32_Os5Never + 164
1 OMGRedesign 0x100171f88 specialized DataManager.userLoggingState() -> DataManager.LoggingUserState (DataManager.swift)
2 OMGRedesign 0x10011e59c specialized APIManager.(login(String, password : String, success : () -> ()?, failure : (Error?) -> ()?) -> ()).(closure #1) (APIManager.swift)
3 OMGRedesign 0x10012b0d0 partial apply for APIManager.(loginUsingStoredTokens(String, success : () -> ()?, failure : (Error?) -> ()?) -> ()).(closure #1) + 4295897296
4 p2_OAuth2 0x1008ea38c _TMaC9p2_OAuth210OAuth2Base + 720
5 p2_OAuth2 0x1008ea1e0 _TMaC9p2_OAuth210OAuth2Base + 292
6 libdispatch.dylib 0x18ebb29a0 _dispatch_client_callout + 16
7 libdispatch.dylib 0x18ebc37a8 _dispatch_barrier_sync_f_slow_invoke + 304
8 libdispatch.dylib 0x18ebb29a0 _dispatch_client_callout + 16
9 libdispatch.dylib 0x18ebb75e8 _dispatch_main_queue_callback_4CF + 996
10 CoreFoundation 0x18fca90c0 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
11 CoreFoundation 0x18fca6cdc __CFRunLoopRun + 1572
12 CoreFoundation 0x18fbd6d94 CFRunLoopRunSpecific + 424
13 GraphicsServices 0x191640074 GSEventRunModal + 100
14 UIKit 0x195e8f130 UIApplicationMain + 208
15 OMGRedesign 0x1000d3ab8 main (Item.swift:129)
16 libdyld.dylib 0x18ebe559c start + 4
以下代码是
func userLoggingState() -> LoggingUserState {
let userDefault = UserDefaults.standard as UserDefaults
let isRegularUserLogged = userDefault.bool(forKey:"regular-user-logged")
let regularUserName = userDefault.string(forKey: "regular-user-username")
let dummyDefaultUser = userDefault.string(forKey: "default-dummy-user")
if isRegularUserLogged == false &&
(regularUserName == nil || regularUserName?.isEmpty == true) &&
(dummyDefaultUser == nil || dummyDefaultUser?.isEmpty == true) {
return .None
}
else if isRegularUserLogged == true &&
(regularUserName != nil && regularUserName?.isEmpty == false) &&
(dummyDefaultUser == nil || dummyDefaultUser?.isEmpty == true) {
return .Regular
}
else if isRegularUserLogged == false &&
(regularUserName == nil || regularUserName?.isEmpty == true) &&
(dummyDefaultUser != nil && dummyDefaultUser?.isEmpty == false) {
return .Dummy
}
else {
PLogWarning("userLogging is in an invalid state, returning None")
return .None
}
}
我不明白为什么会崩溃,因为我无法重现它,所以很难弄明白。
崩溃报告中有一个非常奇怪的事情就是这一行:
15 OMGRedesign 0x1000d3ab8 main (Item.swift:129)
Item.swift是CoreData NSManagedObject派生类。它为什么提到那里?
由于
答案 0 :(得分:2)
事实证明,我们的代码中的这个错误是由“fatalError”命令触发的。