These procedures apply to iOS 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 application:
- Go to one.newrelic.com.
- If applicable: From the Mobile Apps list, select Add a new app.
- From the Get Started page, select iOS as the platform for mobile monitoring.
- Type a name for your mobile app, then select Continue.
- If your installation does not automatically include the prefix header, follow the steps to add the prefix header to your project.
Continue with the steps to configure New Relic for mobile monitoring.
Configure using Objective-C
These procedures to configure your iOS app with CocoaPods and Objective-C also appear on the Get Started page in New Relic.
In the Podfile for your project, add the following line:
pod 'NewRelicAgent'Close your project in Xcode, and update it by running this command from the Terminal in your project directory:
pod installOpen your project in Xcode by running this command from the Terminal in your project directory:
open App.xcworkspaceIn your
APP_NAME-Prefix.pch
project file (generally found in theSupporting Files
folder), include the New Relic header inside the#ifdef __OBJC__ #endif
block:#import <NewRelic/NewRelic.h>In your
AppDelegate.m
file, add this call as the first line ofapplication:didFinishLaunchingWithOptions
, replacingAPP_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.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:SCRIPT=`/usr/bin/find "${SRCROOT}" -name newrelic_postbuild.sh | head -n 1` /bin/sh "${SCRIPT}" "APP_TOKEN"
Clean and build your app, then run it in the simulator or other device.
Configure using Swift
These procedures to configure your iOS app with CocoaPods and Swift also appear on the Get Started page in New Relic.
In the Podfile for your project, add the following line:
pod 'NewRelicAgent'Close your project in Xcode, and update it by running this command from the Terminal in your project directory:
pod installOpen your project in Xcode by running this command from the Terminal in your project directory:
open App.xcworkspaceCreate a bridging header:
- Select File > New > File > Objective-C File.
- Name the file
Placeholder.m
, then select Next. - Select Create, and confirm Xcode's prompt to generate the bridging header.
In your
APP_NAME-Bridging-Header.h
, add the New Relic header:#import "NewRelic/NewRelic.h"In your
AppDelegate.swift
file, add this call as the first line ofapplication:didFinishLaunchingWithOptions
, replacingAPP_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.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:SCRIPT=`/usr/bin/find "${SRCROOT}" -name newrelic_postbuild.sh | head -n 1` /bin/sh "${SCRIPT}" "APP_TOKEN"
Clean and build your app, then run it in the simulator or other device.
Change the logging level (optional)
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)