iOS manual installation

Owner, Admins, or Add-on Managers

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

Install your iOS application

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

For Owners or Admins with existing New Relic accounts, follow these steps to install and configure your iOS application. (If you do not have a New Relic account, see New Relic Mobile.)

  1. Go to rpm.newrelic.com/mobile.
  2. If applicable: From the Mobile Apps index, select "plus-circle" 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 Mobile.

  • To complete the configuration process for a new mobile app later: Go to rpm.newrelic.com/mobile, then select See instructions next to your mobile app name.
  • To upgrade an existing iOS installation: Go to rpm.newrelic.com/mobile > (select an app) > Settings > Installation.

Add the New Relic framework to your app

  1. Download and unzip the iOS SDK for New Relic Mobile.
  2. To add the New Relic Mobile framework to your Xcode project: Use Finder to drag the NewRelicAgent.framework folder into your Xcode project, and drop it onto your project in the Project navigator window.
  3. Follow the prompts to copy items into the destination and to create folder references.
  4. In the General settings of your project, add the following libraries to Linked frameworks and libraries:

    • CoreTelephony.framework
    • SystemConfiguration.framework
    • libc++.tbd
    • libz.tbd
  5. Implement the agent using the appropriate method:

    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 Mobile Agent header at the top of your prefix.pch.
    2. Add +[NewRelic startWithApplicationToken:@"<appToken>"] to the top of -application:didFinishLaunchingWithOptions: in your AppDelegate.m, using the unique application token that is automatically generated.
    Swift
    1. Create a bridging header file:

      1. Select File > New > File > Objective-C File.
      2. Name the file Placeholder.m, then select Next.
      3. Select Create, and confirm Xcode's prompt to generate the bridging header.
      4. Delete Placeholder.m.
    2. Import the New Relic Agent by adding #import "NewRelicAgent/NewRelic.h" to the top of MyApp-Bridging-Header.h.

    3. Add NewRelic.start(withApplicationToken: ">appToken>") 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 PUT_NEW_RELIC_APP_TOKEN_HERE with your application token:

    SCRIPT=`/usr/bin/find "${SRCROOT}" -name newrelic_postbuild.sh | head -n 1`
    /bin/sh "${SCRIPT}" "PUT_NEW_RELIC_APP_TOKEN_HERE"
  7. Clean and build your app, and then run it in the simulator or other device.

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

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)

For more help

Additional documentation resources include:

Recommendations for learning more: