簡體   English   中英

如何在iOS模擬器中調試.app崩潰?

[英]How to debug the .app crash in iOS simulator?

我已經提交了我的應用進行審核,蘋果又回到我身邊說它在啟動時崩潰了。 我將.app文件提交給了Apple,並將其安裝在模擬器上。

xcrun simctl install booted /Users/venkatanandamuri/Desktop/prod\ crash/Myapp.app 

它確實在啟動時崩潰了。

Mac控制台日志未顯示有關模擬器崩潰的任何信息。

我從Xcode設備日志中獲取了崩潰日志:

Last Exception Backtrace:
0   CoreFoundation                  0x1d590a3a8 __exceptionPreprocess + 232
1   libobjc.A.dylib                 0x1d4b0fd00 objc_exception_throw + 59
2   CoreFoundation                  0x1d58229f8 -[NSObject+ 223736 (NSObject) doesNotRecognizeSelector:] + 143
3   CoreFoundation                  0x1d590fd54 ___forwarding___ + 1411
4   CoreFoundation                  0x1d5911b50 _CF_forwarding_prep_0 + 95
5   FBSDKCoreKit                    0x105f67530 0x105f24000 + 275760
6   FBSDKCoreKit                    0x105f673ac 0x105f24000 + 275372
7   FBSDKCoreKit                    0x105f2df28 0x105f24000 + 40744
8   FBSDKCoreKit                    0x105f2b0b0 0x105f24000 + 28848
9   FBSDKCoreKit                    0x105f2afbc 0x105f24000 + 28604
10  FBSDKCoreKit                    0x105f70fe0 0x105f24000 + 315360
11  FBSDKCoreKit                    0x105f7078c 0x105f24000 + 313228
12  FBSDKCoreKit                    0x105f2bb28 0x105f24000 + 31528
13  FBSDKCoreKit                    0x105f34cac 0x105f24000 + 68780
14  Foundation                      0x1d638115c __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_2 + 27
15  CoreFoundation                  0x1d5878acc __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 27
16  CoreFoundation                  0x1d5878a8c ___CFXRegistrationPost_block_invoke + 67
17  CoreFoundation                  0x1d5877f30 _CFXRegistrationPost + 419
18  CoreFoundation                  0x1d5877bbc ___CFXNotificationPost_block_invoke + 99
19  CoreFoundation                  0x1d57ee768 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1503
20  CoreFoundation                  0x1d5877664 _CFXNotificationPost + 715
21  Foundation                      0x1d62727c4 -[NSNotificationCenter postNotificationName:object:userInfo:] + 71
22  UIKitCore                       0x202bd2398 -[UIApplication _stopDeactivatingForReason:] + 1339
23  UIKitCore                       0x20247010c __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 487
24  UIKitCore                       0x202470e5c _performActionsWithDelayForTransitionContext + 119
25  UIKitCore                       0x20246feb8 -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 259
26  UIKitCore                       0x202474ea8 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 363
27  UIKitCore                       0x2027bb904 -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 479
28  FrontBoardServices              0x1d82ccc58 __80-[FBSSceneImpl updater:didUpdateSettings:withDiff:transitionContext:completion:]_block_invoke_3 + 243
29  libdispatch.dylib               0x1d5319884 _dispatch_client_callout + 19
30  libdispatch.dylib               0x1d531ce5c _dispatch_block_invoke_direct + 251
31  FrontBoardServices              0x1d830918c __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 47
32  FrontBoardServices              0x1d8308e08 -[FBSSerialQueue _performNext] + 435
33  FrontBoardServices              0x1d8309404 -[FBSSerialQueue _performNextFromRunLoopSource] + 55
34  CoreFoundation                  0x1d589a444 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 27
35  CoreFoundation                  0x1d589a3c0 __CFRunLoopDoSource0 + 91
36  CoreFoundation                  0x1d5899c7c __CFRunLoopDoSources0 + 179
37  CoreFoundation                  0x1d5894950 __CFRunLoopRun + 987
38  CoreFoundation                  0x1d5894254 CFRunLoopRunSpecific + 451
39  GraphicsServices                0x1d7ad3d8c GSEventRunModal + 107
40  UIKitCore                       0x202bdc4c0 UIApplicationMain + 215
41  MyApp                           0x104d97148 0x104d90000 + 29000
42  libdyld.dylib                   0x1d5350fd8 start + 3

我用符號表示崩潰日志,發現:

Thread 0 Crashed:

0   libsystem_kernel.dylib             0x00000001f1be50dc 0x1f1bc2000 + 143580

指着

NSNotificationName.TimeOutUserInteraction.unsafeMutableAddressor (in MyApp) (InterractionUIApplication.swift:0)

我注釋了與此通知相關的行,並批准了該應用。

令人驚訝的是,與此相關的代碼不會在應用啟動時被調用。 正如我在代碼庫中搜索的那樣,這是沒有可能的,並且該代碼只會在登錄過程中被調用,而不會在應用啟動時被調用。

我不知道為什么它崩潰,為什么在我注釋掉代碼后卻沒有崩潰。

與此通知相關的代碼:

import UIKit

// User Activity Timer

extension NSNotification.Name {
    public static let TimeOutUserInteraction: NSNotification.Name = NSNotification.Name(rawValue: "TimeOutUserInteraction")
}

class InterractionUIApplication: UIApplication {

    static let timeoutInSeconds: TimeInterval = 60 * 10 // 10 minutes
    private var idleTimer: Timer?
    private var enabledUserInteractionTracking: Bool = false

    func startUserInternactionTracking() {
        enabledUserInteractionTracking = true
        resetIdleTimer()
    }

    func stopUserInternactionTracking() {
        enabledUserInteractionTracking = false
        if let idleTimer = idleTimer {
            idleTimer.invalidate()
        }
        idleTimer = nil
    }

    // Resent the timer because there was user interaction.
    func resetIdleTimer() {
        if let idleTimer = idleTimer {
            idleTimer.invalidate()
        }

        idleTimer = Timer.scheduledTimer(timeInterval: InterractionUIApplication.timeoutInSeconds, target: self, selector: #selector(idleTimerExceeded), userInfo: nil, repeats: false)
    }


    // If the timer reaches the limit as defined in timeoutInSeconds, post this notification.
    @objc func idleTimerExceeded() {
        NotificationCenter.default.post(name: Notification.Name.TimeOutUserInteraction, object: nil)
    }
}

並在MyAppManager類中:

 func startUserInternactionTracking()
    {
        (UIApplication.shared as? InterractionUIApplication)?.startUserInternactionTracking()
        NotificationCenter.default.addObserver(self, selector: #selector(onTimeOutUserInteraction), name: Notification.Name.TimeOutUserInteraction, object: nil) //This is the commented out line to make review successful 

    }

    func stopUserInternactionTracking()
    {
        (UIApplication.shared as? InterractionUIApplication)?.stopUserInternactionTracking()
        NotificationCenter.default.removeObserver(self, name: Notification.Name.TimeOutUserInteraction, object: nil)
    }

我確定在應用啟動過程中不會調用startUserInternactionTracking 但是我想知道為什么這是崩潰的原因嗎?

在AppDelegate中,我初始化管理器類:

class AppDelegate: UIResponder, UIApplicationDelegate {

 var window: UIWindow?

 var appManager = MyAppManager()

 .....
}

請不要將此崩潰僅發生在經過測試的蘋果設備上。 預生產版本在我們所有的測試設備中均按預期工作。我缺乏調試此類崩潰的經驗。 我以前從未見過。

有人可以指出我正確的方向嗎?

子類化UIApplication似乎是可能的原因。 根據文檔

子類注釋

大多數應用程序不需要繼承UIApplication。 而是使用應用程序委托來>管理系統與應用程序之間的交互。 如果您的應用必須在系統之前處理傳入事件(一種非常罕見的情況),則可以實現自定義事件或操作調度機制。 為此,請子類化UIApplication並重寫sendEvent( :)和/或sendAction( :to:from:for :)方法。 對於您攔截的每個事件,在處理事件后,通過調用[super sendEvent:event]將其分配回系統。 >截取事件只是很少需要的,並且如果可能,應避免使用。

您實際上是在實例化該子類而不是UIApplication嗎? 為此,您需要創建一個main.swift文件並調用UIApplicationMain(,,,)並從UIApplicationDelegate子類頂部刪除默認的@UIApplicationMain宏。

但是正如文檔所述,似乎並不需要您真正繼承UIApplication,我建議您研究“協調器”模式,該示例從管理應用程序級邏輯的應用程序委托實例化一個AppController類。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM