应用程序在使用 NewRelic 框架的设备上启动时崩溃

App crashes on launch on device with NewRelic framework

我有基于 swift 的应用程序 NewRelicAgent.framework 集成...

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Register the analytics app
    NewRelicAgent.startWithApplicationToken("AA****************************6");

应用程序在 LoginViewController 上崩溃,启动时第一个视图控制器,日志如下 -

0   libsystem_c.dylib               0x00000001978d1690 __sfvwrite + 0
1   libsystem_c.dylib               0x00000001978d8958 __vfprintf + 11352
2   libsystem_c.dylib               0x00000001978f367c __v2printf + 584
3   libsystem_c.dylib               0x0000000197886208 _vsnprintf + 300
4   libsystem_c.dylib               0x0000000197886c54 snprintf_l + 20
5   CoreFoundation                  0x00000001859d7018 __CFStringAppendFormatCore + 11580
6   CoreFoundation                  0x00000001859d42a0 _CFStringCreateWithFormatAndArgumentsAux2 + 244
7   Foundation                      0x000000018681a444 -[NSPlaceholderString initWithFormat:locale:arguments:] + 168
8   Foundation                      0x000000018681a304 +[NSString stringWithFormat:] + 72
9   Zimplifi                        0x00000001001558e0 +[NRMAThreadLocalStore currentThreadDictionary] (NRMAThreadLocalStore.m:238)
10  Zimplifi                        0x00000001001540b8 +[NRMAThreadLocalStore threadLocalTrace] (NRMAThreadLocalStore.m:36)
11  Zimplifi                        0x0000000100154a80 +[NRMAThreadLocalStore prepareSameThread:child:withParent:] (NRMAThreadLocalStore.m:126)
12  Zimplifi                        0x0000000100154500 +[NRMAThreadLocalStore pushChild:forParent:] (NRMAThreadLocalStore.m:91)
13  Zimplifi                        0x0000000100123768 +[NRMATraceController newTraceSetup:parentTrace:] (NRMATraceController.m:310)
14  Zimplifi                        0x0000000100123c6c +[NRMATraceController enterMethod:fromObject:parentTrace:traceCategory:withTimer:] (NRMATraceController.m:374)
15  Zimplifi                        0x0000000100123a40 +[NRMATraceController enterMethod:fromObject:parentTrace:traceCategory:] (NRMATraceController.m:338)
16  Zimplifi                        0x000000010010e92c NRMA__beginMethod (NRMAMethodProfiler.m:1051)
17  Zimplifi                        0x000000010010e500 NRMA__voidParamHandler (NRMAMethodProfiler.m:705)
18  Zimplifi                        0x00000001000677c4 Zimplifi.ZViewController.viewDidLoad (Zimplifi.ZViewController)() -> () (ZViewController.swift:14)
19  Zimplifi                        0x0000000100053d1c @objc Zimplifi.LoginViewController.viewDidLoad (Zimplifi.LoginViewController)() -> () (LoginViewController.swift:27)

LoginViewController 是普通 ZViewController 的子类...

class ZViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

    }
}

class LoginViewController: ZViewController {
...
...
}

我的任何视图控制器或项目中都没有与 NewRelicAgent 相关的任何其他代码(项目目标中的 RunScript 除外)。

有解决办法吗?

编辑:使用 FIX :)

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Register the analytics app
        NewRelicAgent.enableFeatures(NRMAFeatureFlags.NRFeatureFlag_SwiftInteractionTracing);
        NewRelicAgent.startWithApplicationToken("AA****************************6");

        // Your app specific code.......

    }

// Add 'dynamic' before viewDidLoad method and probably any other view life cycle method or method to be traced for analytics
class ZViewController: UIViewController {

    override dynamic func viewDidLoad() {
         super.viewDidLoad()
         // Your implementation...
    }
}

解决方法之一是避免 UIViewController 的多级继承 -

class LoginViewController: UIViewController {
...
...
}

似乎当前 NewRelic 框架在继承/swift 采用方面存在一些问题。

Swift 应用程序需要在 New Relic 中进行一些额外的配置:

https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/getting-started/enabling-swift-interaction-traces

您是否已将 dynamic 声明修饰符添加到您的方法中并使用功能标志启用 Swift 交互跟踪?