简体   繁体   中英

How to debug the .app crash in iOS simulator?

I have submitted my app to review and apple got back to me saying it crashes in launch. I got the .app file submitted to apple, and I installed it on the simulator.

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

It indeed crashed on launch.

The Mac console log shows nothing about the crash on simulator.

I got the crash log from Xcode device logs:

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

and I symbolicated the crash log , I found:

Thread 0 Crashed:

0   libsystem_kernel.dylib             0x00000001f1be50dc 0x1f1bc2000 + 143580

points to

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

I commented out the lines related to this notification, and the app got approved.

Surprisingly the code related to this would not get called on app launch. There is no possibility, as I searched the codebase, and this code would only be called during a sign in process but NOT ON app launch.

I wonder why it crashes, and why it didn't after I commented out the code.

Code related to this notification:

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)
    }
}

and in MyAppManager class:

 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)
    }

I'm sure that startUserInternactionTracking is not called during app launch. But I wonder why this is the reason for crash ?

In AppDelegate, I initialize the manager class:

class AppDelegate: UIResponder, UIApplicationDelegate {

 var window: UIWindow?

 var appManager = MyAppManager()

 .....
}

Please not this crash only happened on the device apple tested. The pre-prod build worked as expected in all of our test devices .I'm lack of experience to debug this kind of crash. I've never seen this before.

Can someone point me in right direction ?

Subclassing UIApplication looks like a possible cause. According to the documentation

Subclassing Notes

Most apps do not need to subclass UIApplication. Instead, use an app delegate to > manage interactions between the system and the app. If your app must handle incoming events before the system does—a very rare situation—you can implement a custom event or action dispatching mechanism. To do > this, subclass UIApplication and override the sendEvent( :) and/or the sendAction( :to:from:for:) methods. For every event you intercept, dispatch it back to the system by calling [super sendEvent:event] after you handle the event. > Intercepting events is only rarely required and you should avoid it if possible.

Are you actually instantiating that subclass instead of UIApplication? To do this you would need to create a main.swift file and call UIApplicationMain(,,,) and remove the default @UIApplicationMain macro from the top of your UIApplicationDelegate subclass.

But as the docs say, it doesn't seem like you actually need to subclass UIApplication, I suggest you look into the "coordinator" pattern instantiate an AppController class from your app delegate that manages app level logic.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM