• /
  • EnglishEspañol日本語한국어Português
  • EntrarComeçar agora

Swift Package Manager manual installation

We recommend that you use our guided install to set up iOS monitoring. However, if you need to install the agent manually, follow the steps below to install the New Relic iOS agent with Swift Package Manager.

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:

  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 Swift Package Manager

  1. Select File > Swift Packages > Add Package Dependency....

  2. Add the Github URL of the Package file:

    https://github.com/newrelic/newrelic-ios-agent-spm

    Dica

    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.

  3. Select the NewRelic package product, select your target, and select Finish.

  4. In your AppDelegate.swift file, add this call as the first line of applicationDidFinishLaunchWithOptions, replacing APP_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")

    Importante

    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.

  5. Based on your iOS agent version, add the build script below to your target's Build Phases. Make sure the script is the very last build script, and replace APP_TOKEN with your application token.

    • For iOS agent 7.4.0 or higher:
    bash
    $
    ARTIFACT_DIR="${BUILD_DIR%Build/*}"
    $
    SCRIPT=`/usr/bin/find "${SRCROOT}" "${ARTIFACT_DIR}" -type f -name run-symbol-tool | head -n 1`
    $
    /bin/sh "${SCRIPT}" "APP_TOKEN"
    • For iOS Agent 7.3.8 or lower:
    bash
    $
    SCRIPT=`/usr/bin/find "${SRCROOT}" -name newrelic_postbuild.sh | head -n 1`
    $
    /bin/sh "${SCRIPT}" "APP_TOKEN"
  6. (Optional) Add the following lines to your build script above to skip symbol upload during debugging:

    bash
    $
    if [ ${CONFIGURATION} = "Debug" ]; then
    $
    echo "Skipping DSYM upload CONFIGURATION: ${CONFIGURATION}"
    $
    exit 0
    $
    fi
  7. If there is a checkbox that says "Run script: Based on Dependency analysis", make sure it is unchecked.

  8. Clean and build your app, then run it in the simulator or other device.

Este documento ajudou você na instalação?

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:

  1. De-integrate New Relic Swift package from the Xcode project.
  2. Run these commands from the terminal to delete spm caches:
    bash
    $
    rm -rf ~/Library/Caches/org.swift.swiftpm
    $
    rm -rf ~/Library/org.swift.swiftpm
  3. Delete derived data using Xcode.
  4. Re-integrate the New Relic Swift package into the Xcode project.

(Optional) Change the logging level

By default, the iOS agent logs at the info level. you can change the log level to collect more or less data. There are six supported log levels:

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

Importante

Only increase the log level to verbose or higher for debugging, not for release builds.

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

NRLogger.setLogLevels(NRLogLevelALL.rawValue)
Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.