Search code examples
ioscrashnewrelicviewdidload

App crashes on launch on device with NewRelic framework


I have swift based app with NewRelicAgent.framework integration...

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

The app crashes on LoginViewController, first view controller on launch, with following log -

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 is subclass of common ZViewController....

class ZViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

    }
}

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

I don't have any other code related to NewRelicAgent in any of my view controller or in project (except the RunScript in project target).

Any idea to resolve it?

EDIT: With 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...
    }
}

Solution

  • Swift apps require some additional configuration in New Relic:

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

    Have you added the dynamic declaration modifier to your methods and enabled Swift Interaction traces using the feature flag?