【问题标题】:How to debug the .app crash in iOS simulator?如何在 iOS 模拟器中调试 .app 崩溃?
【发布时间】:2019-11-15 07:33:54
【问题描述】:

我已提交我的应用以供审核,但苹果回复我说它在启动时崩溃。我得到了提交给苹果的.app文件,并在模拟器上安装了它。

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

 .....
}

请注意,此崩溃仅发生在经过 Apple 测试的设备上。预产品构建在我们所有的测试设备中都按预期工作。我缺乏调试这种崩溃的经验。我以前从未见过这种情况。

有人能指出我正确的方向吗?

【问题讨论】:

  • 进展如何?是 UIApplication 的问题吗?
  • 还是要查,要等app审核后才能查到。审核后我会更新我的问题。感谢您的帮助:)

标签: ios xcode debugging


【解决方案1】:

子类化 UIApplication 看起来是一个可能的原因。根据documentation

子类化注释

大多数应用程序不需要子类化 UIApplication。相反,使用应用委托来 > 管理系统和应用之间的交互。 如果您的应用程序必须在系统之前处理传入事件——这是非常罕见的 情况——您可以实现自定义事件或动作调度机制。为此,请将 UIApplication 子类化并覆盖 sendEvent(:) 和/或 sendAction(:to:from:for:) 方法。对于您拦截的每个事件,调度它 处理完事件后调用 [super sendEvent:event] 返回系统。 > 很少需要拦截事件,您应该尽可能避免。

您实际上是在实例化该子类而不是 UIApplication 吗?为此,您需要创建一个 main.swift 文件并调用 UIApplicationMain(,,,) 并从 UIApplicationDelegate 子类的顶部删除默认的 @UIApplicationMain 宏。

但正如文档所说,您似乎不需要子类化 UIApplication,我建议您查看 "coordinator" pattern 从管理应用级逻辑的应用委托中实例化一个 AppController 类。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-09
    • 2012-06-28
    • 1970-01-01
    • 2011-12-08
    • 2021-08-27
    相关资源
    最近更新 更多