CocoaPods installation

These procedures apply to iOS and tvOS apps using Cocoapods. For other types, see iOS installation and configuration.

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 or tvOS application:

  1. Go to one.newrelic.com.
  2. (If applicable) From the Mobile Apps list, 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, then select Continue.

Continue with the steps to configure New Relic for mobile monitoring.

Configure using Objective-C

These procedures to configure your iOS/tvOS app with CocoaPods and Objective-C also appear on the Get Started page in New Relic.

  1. In the Podfile for your project, add the following line:

    pod 'NewRelicAgent'
  2. Close your project in Xcode, and update it by running this command from the Terminal in your project directory:

    pod install
  3. Open your project in Xcode by running this command from the Terminal in your project directory:

    open App.xcworkspace
  4. In your AppDelegate.m file, include the New Relic header:

    #import <NewRelic/NewRelic.h>
  5. In your AppDelegate.m file, add this call as the first line of application:didFinishLaunchingWithOptions, replacing APP_TOKEN with your application token:

    [NewRelic startWithApplicationToken:@"APP_TOKEN"];

    Important

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

  6. Add a build script to your target's Build Phases. Ensure the new build script is the very last build script. 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
  1. Clean and build your app, then run it in the simulator or on another device.

Configure using Swift

These procedures to configure your iOS/tvOS app with CocoaPods and Swift also appear on the Get Started page in New Relic.

  1. In the Podfile for your project, add the following line:

    pod 'NewRelicAgent'
  2. Close your project in Xcode, and update it by running this command from the terminal in your project directory:

    pod install
  3. Open your project in Xcode by running this command from the terminal in your project directory:

    open App.xcworkspace
  4. In your AppDelegate.swift, add the New Relic header: (If your app is written in SwiftUI, follow these instructions to add an AppDelegate to your project.)

    import NewRelic
  5. In your AppDelegate.swift file, add this call as the first line of application:didFinishLaunchingWithOptions, replacing APP_TOKEN with your application token:

    NewRelic.start(withApplicationToken:"APP_TOKEN")

    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.

  6. Add a build script to your target's build phases. Ensure the new build script is the very last build script. 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
  1. Clean and build your app, then run it in the simulator or on another device.

Did this doc help with your installation?

Change the logging level (optional)

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

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

To increase your logging level in the app, add this method call before calling NewRelic.start(withApplicationToken):

[NRLogger setLogLevels:NRLogLevelALL];

For Swift apps:

NRLogger.setLogLevels(NRLogLevelALL.rawValue)