These procedures apply to iOS/tvOS apps using Swift Package Manager. 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/tvOS 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.
Continue with the steps to configure New Relic for mobile monitoring.
Configure using Swift Package Manager
Select File > Swift Packages > Add Package Dependency....
Add the Github URL of the Package file:
https://github.com/newrelic/newrelic-ios-agent-spmTip
If you receive an
artifact of binary target 'NewRelic' failed extraction: The operation couldn’t be completed. (TSCBasic.StringError error 1.)
error when extracting the package, please close Xcode, delete the Derrived Data folder, re-open Xcode, and try again.Select the NewRelic package product, select your target, and select Finish.
In your
AppDelegate.swift
file, add this call as the first line ofapplicationDidFinishLaunchWithOptions
, replacingAPP_TOKEN
with your application token: (If your app is written in SwiftUI, follow these instructions to add an AppDelegate to your project.)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:iOS agent 7.4.0 or higher:
ARTIFACT_DIR="${BUILD_DIR%Build/*}SourcePackages/artifacts"SCRIPT=`/usr/bin/find "${SRCROOT}" "${ARTIFACT_DIR}" -type f -name run-symbol-tool | head -n 1`/bin/sh "${SCRIPT}" "APP_TOKEN"iOS agent 7.3.8 or lower:
SCRIPT=`/usr/bin/find "${SRCROOT}" -name newrelic_postbuild.sh | head -n 1`if [ -z "${SCRIPT}"]; thenARTIFACT_DIR="${BUILD_DIR%Build/*}SourcePackages/artifacts"SCRIPT=`/usr/bin/find "${ARTIFACT_DIR}" -name newrelic_postbuild.sh | head -n 1`fi/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" ]; thenecho "Skipping DSYM upload CONFIGURATION: ${CONFIGURATION}"exit 0fiIf there is a checkbox below Run script that says "Run script: Based on Dependency analysis" please make sure it is not checked.
Clean and build your app, then run it in the simulator or other device.
Did this doc help with your installation?
Troubleshooting
You might see the following errors when adding the Swift package:
- Artifact does not match checksum
- Cannot download framework from remoteSourceControl
If you see these types of errors, try the following:
- De-integrate New Relic Swift package from the Xcode project.
- Run these commands from the terminal to delete spm caches:rm -rf ~/Library/Caches/org.swift.swiftpmrm -rf ~/Library/org.swift.swiftpm
- Delete derived data using Xcode.
- Re-integrate the New Relic Swift package into the Xcode project.
Change the logging level (optional)
By default the New Relic 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.rawValue)