iOS manual installation

To install and configure New Relic functionality with your iOS/tvOS applications, follow these procedures. If your iOS/tvOS app uses Cocoapods, follow the Cocoapods installation procedures.

Install your iOS application

As part of the installation process, New Relic automatically generates an application token. This is a 40-character hexadecimal string for authenticating each mobile app you monitor in New Relic.

To install and configure your iOS/tvOS application:

  1. Go to one.newrelic.com.
  2. If applicable: From the Mobile Apps index, select Add a new app.
  3. From the Get started page, select iOS as the platform for mobile monitoring.
  4. Type a name for your mobile app, and select Continue.

Continue with the steps to configure New Relic.

Add the New Relic framework to your app

  1. Download and unzip the iOS agent.

  2. To add the New Relic framework to your Xcode project:

  3. Using Finder, drag the NewRelic.xcframework folder into your Xcode project and drop it onto your project in the Project navigator window, under Frameworks, Libraries, and Embedded Content.

  4. Make sure Embed & Sign is selected under the Embed dropdown menu.

  5. Implement the agent using the appropriate method:

    Important

    To ensure proper instrumentation, you must call the agent on the first line of didFinishLaunchingWithOptions(), and run the agent on the main thread. Starting the call later, on a background thread, or asynchronously can cause unexpected or unstable behavior.

    Language

    Procedure

    Objective-C

    1. To start the agent, import the New Relic header by adding #import <NewRelic/NewRelic.h> at the top of your AppDelegate.m.
    2. Add +[NewRelic startWithApplicationToken:@"APP_TOKEN"] to the top of -application:didFinishLaunchingWithOptions: in your AppDelegate.m, using the unique application token that is automatically generated.

    Swift

    1. Import the New Relic agent by adding import NewRelic to the top of AppDelegate.swift. (If your app is written in SwiftUI, follow these instructions to add an AppDelegate to your project.)
    2. Add NewRelic.start(withApplicationToken: "APP_TOKEN") to the top of application(_:didFinishLaunchingWithOptions:) in your AppDelegate.swift using the unique application token that is automatically generated.
  6. Add a build script to your target's build phases. Ensure the new build script is the very last build phase, then paste the following, replacing APP_TOKEN with your application token:

    For iOS agent 7.4.0 or higher:

    SCRIPT=`/usr/bin/find "${SRCROOT}" -name run-symbol-tool | head -n 1`
    /bin/sh "${SCRIPT}" "APP_TOKEN"

    For iOS agent 7.3.8 or lower:

    SCRIPT=`/usr/bin/find "${SRCROOT}" -name newrelic_postbuild.sh | head -n 1`
    /bin/sh "${SCRIPT}" "APP_TOKEN"

    OPTIONAL:

    Add the following lines to your build script above the existing lines to skip symbol upload during debugging:

    if [ ${CONFIGURATION} = "Debug" ]; then
    echo "Skipping DSYM upload CONFIGURATION: ${CONFIGURATION}"
    exit 0
    fi
    ```
  7. Clean and build your app, and then run it in the simulator or other device.

Did this doc help with your installation?

Optional: Execute a demo crash

If you have trouble getting your app to crash, the New Relic agent provides an API to execute a demo crash.

Recommendation: Add one of these lines of code to a button click event handler as applicable:

Language

Code

Objective-C

Crash:

[NewRelic crashNow];

Crash with log message:

[NewRelic crashNow:@"<reason>"];

Swift

Crash:

NewRelic.crashNow()

Crash with log message:

NewRelic.crashNow(_ message:)

Optional: Change the logging level

By default the New Relic agent will log at the info level. Increasing the log level to verbose or higher priority is only encouraged for debugging and not for release builds. Verbose level or higher priority will log all API interactions with the New Relic server. Six log levels are available for mobile apps monitoring:

  • none
  • error
  • warning
  • info
  • verbose
  • ALL

To increase your logging level in the app, add the following method:

Language

Code

Objective-C

Just before calling startWithApplicationToken in AppDelegate.m, add:

[NRLogger setLogLevels:NRLogLevelALL];

Swift

Just before calling start(withApplicationToken:) in AppDelegate.swift, add:

NRLogger.setLogLevels(NRLogLevelALL.rawValue)