了解 iOS 应用的 Firebase Crashlytics 报告

Understanding Firebase Crashlytics report for iOS app

我有一个 iOS 应用程序使用 Firebase Crashlytics 报告崩溃。现在我有一份崩溃报告,但我的问题是我无法从这份报告中理解到底是什么导致了崩溃。

Crashlytics 报告:

Crashed: com.apple.main-thread
0  Nail it                        0x104db77a8 CaseDetailsViewController.getbaseData() + 253 
(CaseDetailsViewController.swift:253)
1  Nail it                        0x104db5168 CaseDetailsViewController.viewDidLoad() + 4335047016 (<compiler-generated>:4335047016)
2  Nail it                        0x104db521c @objc CaseDetailsViewController.viewDidLoad() + 4335047196 (<compiler-generated>:4335047196)
3  UIKitCore                      0x185d11658 -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 100
4  UIKitCore                      0x185d160e8 -[UIViewController loadViewIfRequired] + 936
5  UIKitCore                      0x185d164f0 -[UIViewController view] + 28
6  UIKit                          0x1b913374c -[UIViewControllerAccessibility dismissViewControllerWithTransition:completion:] + 268
7  UIKitCore                      0x185d28d6c -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 508
8  UIKitCore                      0x185d2b474 -[UIViewController dismissViewControllerAnimated:completion:] + 132
9  UIKit                          0x1b91333c0 -[UIViewControllerAccessibility dismissViewControllerAnimated:completion:] + 120
10 Nail it                        0x104db98ec @objc CaseDetailsViewController.backButton(_:) + 4335065324 (<compiler-generated>:4335065324)
11 UIKitCore                      0x18635a72c -[UIApplication sendAction:to:from:forEvent:] + 96
12 UIKitCore                      0x185a05474 __45-[_UIButtonBarTargetAction _invoke:forEvent:]_block_invoke + 80
13 UIKitCore                      0x185a05304 -[_UIButtonBarTargetAction _invoke:forEvent:] + 236
14 UIKitCore                      0x18635a72c -[UIApplication sendAction:to:from:forEvent:] + 96
15 UIKitCore                      0x185d6aed0 -[UIControl sendAction:to:forEvent:] + 240
16 UIKitCore                      0x185d6b228 -[UIControl _sendActionsForEvents:withEvent:] + 396
17 UIKitCore                      0x185d6a24c -[UIControl touchesEnded:withEvent:] + 516
18 UIKitCore                      0x18639449c -[UIWindow _sendTouchesForEvent:] + 1280
19 UIKitCore                      0x186395c64 -[UIWindow sendEvent:] + 3468
20 UIKitCore                      0x1863718ec -[UIApplication sendEvent:] + 344
21 UIKit                          0x1b90db80c -[UIApplicationAccessibility sendEvent:] + 96
22 UIKitCore                      0x1863f2970 __dispatchPreprocessedEventFromEventQueue + 6808
23 UIKitCore                      0x1863f54ec __handleEventQueueInternal + 5364
24 UIKitCore                      0x1863ed168 __handleHIDEventFetcherDrain + 140
25 CoreFoundation                 0x182223ad8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
26 CoreFoundation                 0x182223a30 __CFRunLoopDoSource0 + 80
27 CoreFoundation                 0x1822231b8 __CFRunLoopDoSources0 + 184
28 CoreFoundation                 0x18221e1e8 __CFRunLoopRun + 788
29 CoreFoundation                 0x18221dba8 CFRunLoopRunSpecific + 424
30 GraphicsServices               0x18c394344 GSEventRunModal + 160
31 UIKitCore                      0x1863593e4 UIApplicationMain + 1932
32 Nail it                        0x104d797cc main + 16 (AppDelegate.swift:16)
33 libdyld.dylib                  0x1820a58f0 start + 4

下面是来自 CasesDetails View Controller 的函数 getBaseData():

func getbaseData(){
    
    let userDefaults = UserDefaults.standard
    mobile = userDefaults.value(forKey: "mobile") as! String
    altenativeMobile = userDefaults.string(forKey: "altenativeMobile") ?? mobile
    privateKey = userDefaults.value(forKey: "privateKey") as! String
    
    
    ////reading JSON
    let categoriesJsonString = userDefaults.value(forKey: "categoriesString") as! String
    
    let data = categoriesJsonString.data(using: .utf8)!
    if let json = try? JSON(data: data) {
        
        let arrayCats =  json["content"][1]["caseMappings"][caseCategoryGlobal].array
        if(isNoSubsGlob == 0){
        if let arrayCatsCount = arrayCats?.count {
            print("The array has been created with \(arrayCatsCount) element")
            print("sub1Glob= \(sub1Glob) & sub2Glob= \(sub2Glob)")
            for var i in 0..<arrayCatsCount{
                
                let sub1 = json["content"][1]["caseMappings"][caseCategoryGlobal][i]["sub1"].string!
                let sub2 = json["content"][1]["caseMappings"][caseCategoryGlobal][i]["sub2"].string ?? ""
                
                
                if (sub1 == sub1Glob && sub2 == sub2Glob){
                    
                    departmentId = json["content"][1]["caseMappings"][caseCategoryGlobal][i]["departmentId"].int!
                    WorkTypeId = json["content"][1]["caseMappings"][caseCategoryGlobal][i]["categoryId"].int!
                    issueCode = json["content"][1]["caseMappings"][caseCategoryGlobal][i]["id"].int!
                    
                    
                    
                }
                
            }
        }
        }else{
            departmentId = json["content"][1]["caseMappings"][caseCategoryGlobal][0]["departmentId"].int!
            WorkTypeId = json["content"][1]["caseMappings"][caseCategoryGlobal][0]["categoryId"].int!
            issueCode = json["content"][1]["caseMappings"][caseCategoryGlobal][0]["id"].int!

        }
        
        
    }
    
    contactNumberText.text = altenativeMobile
    
}

第 235 行是 (contactNumberText.text = altenativeMobile) 作为上面代码的最后一行

所有 UI 东西都应该在主线程上执行,这就是您的崩溃报告显示的内容(由于主线程导致崩溃。)

所以你的最后一行应该是:

DispatchQueue.main.async {
    self.contactNumberText.text = altenativeMobile
}

更新此行,您的崩溃将得到修复。