Set up OneAgent for your iOS apps

iOS tvOS

To monitor your mobile app with Dynatrace, you need to create an application in Dynatrace and set up OneAgent for your mobile app.

After that, you might also want to instrument your app's SwiftUI controls, fine-tune the auto-instrumentation features via configuration keys, or capture additional details via manual instrumentation.

Create an app in Dynatrace

To create a mobile application in Dynatrace

  1. In Dynatrace, go to Mobile.
  2. Select Create mobile app.
  3. Enter a name for your application and select Create mobile app. The application settings page opens.

Set up OneAgent

Use CocoaPods, Swift Package Manager, or Carthage to set up Real User Monitoring for your app. You can also follow the manual approach, though it's better to use one of the automated approaches.

You can set up OneAgent as a dynamic XCFramework, static XCFramework (available for OneAgent for iOS version 8.237+), traditional framework, or static library.

You can't combine the static Dynatrace XCFramework and the dynamic Session Replay XCFramework. For Session Replay, both XCFrameworks have to be dynamic.

If you use the static XCFramework, the traditional framework, or the static library to instrument your iOS app, you'll need to perform some additional steps.

Set up OneAgent with CocoaPods

  1. Add Dynatrace OneAgent as a dependency within the CocoaPods Podfile specification. You can do this by setting up OneAgent as a dynamic XCFramework, static XCFramework, traditional framework, or static library.

    The traditional framework and the static library were deprecated as they don't support ARM64 Simulator architecture. This architecture is required to build apps on Mac computers with Apple silicon.

  2. Add your application's identification keys to the Info.plist file. Check the instrumentation wizard in Dynatrace for the exact values.

  3. Trigger your project build once before using OneAgent SDK or any import declarations in Xcode.

CocoaPods automatically adds OneAgent to your iOS project during the build process.

For more information on Podfiles, see Podfile Syntax Reference.

Set up OneAgent with Swift Package Manager

  1. In Xcode, select File > Swift Packages > Add Package Dependency.
  2. Add https://github.com/Dynatrace/swift-mobile-sdk.git as the package repository URL.
  3. Select only one package product:
    • Dynatrace to add only OneAgent
    • DynatraceSessionReplay to add both OneAgent and the Session Replay on crashes module

      Do not select DynatraceSessionReplay for tvOS, as Session Replay is not available for this operating system.

    • Dynatrace-Static to add only OneAgent as a static XCFramework
  4. Perform additional steps depending on the framework you use.
    1. In Xcode, go to the Build Settings tab of your application target.
    2. Expand Linking.
    3. Add the -ObjC linker flag to Other Linker Flags.

    You can skip this step if your application doesn't have Swift code or doesn't need access to the Dynatrace framework.

    We assume that you already created the Objective-C bridging header file for your Swift code in Xcode.

    1. Make sure you set the bridging header file in your application target build settings.
    2. Add the following import line to the bridging header file:
      #import <DynatraceStatic/Dynatrace.h>
    1. In Xcode, go to the Build Settings tab of your application target.
    2. Expand Linking.
    3. Add the -ObjC linker flag to Other Linker Flags.

    You can skip this step if your application doesn't have Swift code or doesn't need access to the Dynatrace library.

    We assume that you already created the Objective-C bridging header file for your Swift code in Xcode.

    1. Make sure you set the bridging header file in your application target build settings.
    2. Add the following import line to the bridging header file:
      #import Dynatrace.h
  5. Add your application's identification keys to the Info.plist file. Check the instrumentation wizard in Dynatrace for the exact values.
  6. Trigger your project build once before using OneAgent SDK or any import declarations in Xcode.

To update the package version rule, double-click the product entry in the Swift Packages tab within the Xcode project settings. To change the product selection, remove the package and add it again.

To update the package, select File > Swift Packages > Update to Latest Package Versions in Xcode.

When switching from Carthage to Swift Package Manager, remove the script that you previously added in Xcode to remove iOS Simulator architecture from the release binary. Otherwise, you might have issues when building your project in Xcode 15+.

Set up OneAgent with Carthage

  1. Add binary "https://mobileagent.downloads.dynatrace.com/ios/carthage/dynatrace.json" ~> 8.279 to your Cartfile.
  2. Run carthage update --use-xcframeworks.
    If you use the deprecated traditional Dynatrace.framework framework, run carthage update.
  3. Add the following framework or frameworks from the Carthage/Build folder to the Frameworks, Libraries and Embedded Content section located within the General tab of your application target, and set it or them to Embed & Sign.
    • Dynatrace.xcframework to add only OneAgent
    • Dynatrace.xcframework and DynatraceSessionReplay.xcframework to add both OneAgent and the Session Replay on crashes module

      Do not add DynatraceSessionReplay.xcframework for tvOS, as Session Replay is not available for this operating system.

  4. Perform some additional steps depending on the framework you use.
    1. In Xcode, go to the Build Settings tab of your application target.
    2. Expand Linking.
    3. Add the -ObjC linker flag to Other Linker Flags.
    1. In Xcode, go to the General tab of your application target.
    2. Expand Frameworks, Libraries, and Embedded Content.
    3. Add the libc++.tbd library.

    You might need to add this library twice. In our internal tests, the library was linked to the project tree only after we added the library a second time.

    You can skip this step if your application doesn't have Swift code or doesn't need access to the Dynatrace framework.

    We assume that you already created the Objective-C bridging header file for your Swift code in Xcode.

    1. Make sure you set the bridging header file in your application target build settings.
    2. Add the following import line to the bridging header file:
      #import <DynatraceStatic/Dynatrace.h>
    1. In Xcode, add a Run Script phase as the last Build Phase of your application target.

    2. Add the following script:

      APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
      find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
      do
      FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
      FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
      EXTRACTED_ARCHS=()
      for ARCH in $ARCHS
      do
      lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
      EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
      done
      lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
      rm "${EXTRACTED_ARCHS[@]}"
      rm "$FRAMEWORK_EXECUTABLE_PATH"
      mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"
      done
    3. Select Run script: For install builds only.

    This removes the iOS Simulator architecture from your release binary used for AppStore Connect upload.

    1. In Xcode, go to the Build Settings tab of your application target.
    2. Expand Linking.
    3. Add the -ObjC linker flag to Other Linker Flags.

    You can skip this step if your application doesn't have Swift code or doesn't need access to the Dynatrace library.

    We assume that you already created the Objective-C bridging header file for your Swift code in Xcode.

    1. Make sure you set the bridging header file in your application target build settings.
    2. Add the following import line to the bridging header file:
      #import Dynatrace.h
  5. Add your application's identification keys to the Info.plist file. Check the instrumentation wizard in Dynatrace for the exact values.
  6. Trigger your project build once before using OneAgent SDK or any import declarations in Xcode.

Set up OneAgent manually

  1. Access the mobile instrumentation wizard.

  2. Select iOS, and then go to the Developer tab.

  3. Follow the provided instructions.

    Add Dynatrace.xcframework to have only OneAgent.
    Add both Dynatrace.xcframework and DynatraceSessionReplay.xcframework to have both OneAgent and the Session Replay on crashes module.

    Do not add DynatraceSessionReplay.xcframework for tvOS, as Session Replay is not available for this operating system.

  4. Perform some additional steps depending on the framework you use.

    1. In Xcode, go to the Build Settings tab of your application target.
    2. Expand Linking.
    3. Add the -ObjC linker flag to Other Linker Flags.
    1. In Xcode, go to the General tab of your application target.
    2. Expand Frameworks, Libraries, and Embedded Content.
    3. Add the libc++.tbd library.

    You might need to add this library twice. In our internal tests, the library was linked to the project tree only after we added the library a second time.

    You can skip this step if your application doesn't have Swift code or doesn't need access to the Dynatrace framework.

    We assume that you already created the Objective-C bridging header file for your Swift code in Xcode.

    1. Make sure you set the bridging header file in your application target build settings.
    2. Add the following import line to the bridging header file:
      #import <DynatraceStatic/Dynatrace.h>
    1. In Xcode, add a Run Script phase as the last Build Phase of your application target.

    2. Add the following script:

      APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
      find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
      do
      FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
      FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
      EXTRACTED_ARCHS=()
      for ARCH in $ARCHS
      do
      lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
      EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
      done
      lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
      rm "${EXTRACTED_ARCHS[@]}"
      rm "$FRAMEWORK_EXECUTABLE_PATH"
      mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"
      done
    3. Select Run script: For install builds only.

    This removes the iOS Simulator architecture from your release binary used for AppStore Connect upload.

    1. In Xcode, go to the Build Settings tab of your application target.
    2. Expand Linking.
    3. Add the -ObjC linker flag to Other Linker Flags.

    You can skip this step if your application doesn't have Swift code or doesn't need access to the Dynatrace library.

    We assume that you already created the Objective-C bridging header file for your Swift code in Xcode.

    1. Make sure you set the bridging header file in your application target build settings.
    2. Add the following import line to the bridging header file:
      #import Dynatrace.h
  5. Trigger your project build once before using OneAgent SDK or any import declarations in Xcode.

Access mobile instrumentation wizard

The mobile instrumentation wizard in Dynatrace provides you with get-started instructions on instrumenting your iOS apps. To follow more detailed instructions, go to the Set up OneAgent section on this page.

The wizard also contains code snippets with your app's identification keys that you'll need to add to the Info.plist file.

  1. Go to Mobile.
  2. Select the mobile application that you want to configure.
  3. Select More () > Edit in the upper-right corner of the tile with your application name.
  4. From the application settings, select Instrumentation wizard.

Known limitations

  • We don't recommend using several monitoring tools simultaneously with crash reporting or web request instrumentation functionality enabled. This might cause compatibility issues, reporting of wrong or invalid information, and loss of monitoring and crash data. Nevertheless, if you decide to do so, verify via manual testing that these tools are compatible.

  • To use both Dynatrace and Firebase, do one of the following.

    Follow only one of the approaches above; don't perform both actions.

  • To use both Dynatrace and mPaaS, do one of the following.

    Follow only one of the approaches above; don't perform both actions.

  • An auto-instrumented application can't carry out functions such as Dynatrace.shutdown() or Dynatrace .flushEvents(). You can manually insert these methods and other user-defined actions and events before performing auto-instrumentation.

  • The following controls can't be used to create autogenerated actions:

    • Gestures
    • Certain UIBarButton items, including custom UIBarButton items added to the navigation bar by a storyboard (such as info) that use segues to transition to other views.