To install and configure New Relic 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 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 index, select Add a new app.
- From the Get started page, select XCFramework as the platform for mobile monitoring.
- 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
Download and unzip the iOS SDK for New Relic.
To add the New Relic 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, under Frameworks, Libraries, and Embedded Content. Make sure Embed & Sign is selected under the Embed dropdown menu.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
- To start the agent: Import the New Relic header at the top of your
prefix.pch
. - Add
+[NewRelic startWithApplicationToken:@"<appToken>"]
to the top of-application:didFinishLaunchingWithOptions:
in yourAppDelegate.m
, using the unique application token that is automatically generated.
Swift
Create a bridging header file:
- 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.
- Delete
Placeholder.m
.
Import the New Relic agent by adding
#import "NewRelic/NewRelic.h"
to the top ofMyApp-Bridging-Header.h
.Add
NewRelic.start(withApplicationToken: ">appToken>")
to the top ofapplication(_:didFinishLaunchingWithOptions:)
in yourAppDelegate.swift
using the unique application token that is automatically generated.
- To start the agent: Import the New Relic header at the top of your
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"
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:
Crash with log message:
|
Swift | Crash:
Crash with log 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
|
Swift | Just before calling
|