Installing and Configuring the eG Mobile Agent for iOS

The procedure for installing and configuring the eG mobile agent for iOS varies according to the programming language used for building the target application.

iOS applications are typically built using one of the following programming languages:

  • Swift: Building iOS applications using Swift is the modern standard for Apple development. Apple relies on Swift as its primary programming language, paired with SwiftUI for building user interfaces and Xcode as the official integrated development environment.

  • Objective-C: Objective-C was the original foundational language for building iOS applications before Apple introduced Swift in 2014. It is an object-oriented programming language that adds Smalltalk-style messaging mechanics to standard ANSI C. Till this day, Objective-C remains critically important for maintaining large legacy apps, integrating high-performance C++ code, and interfacing with low-level Apple frameworks.

The sections below discuss how to install and configure the mobile agent where each of the aforesaid programming languages are used.

Installing and Configuring the eG Mobile Agent for an iOS Application Built Using Swift

For this, follow the steps below:

  1. Login to the application host.

  2. Then, open the browser, connect to the eG management console, and then login to the eG administrative interface.

  3. Follow the Infrastructure -> Add /Modify menu sequence. Figure 1 will appear. In Figure 1, pick Mobile RUM as the Component type, and click the Add New Component button to add a new Mobile RUM component.

    Selecting Mobile RUM as the Component type

    Figure 1 : Selecting Mobile RUM as the Component type

  4. Figure 2 will then appear. Provide a Nick name for the iOS application you want to monitor.

    Managing iOS App as a Mobile RUM Component

    Figure 2 : Adding the target iOS application as a Mobile RUM component

  5. Then, select the Mobile RUM collector to which the eG Mobile Agent should send the performance metrics it gathers from the target application.

  6. Next, assign a Remote agent to the Mobile RUM component. This is the agent that will pull metrics from the Mobile RUM collector and reports the same to the eG manager.

  7. To install the eG mobile agent on iOS, set Application type as Native.

  8. Finally, click the Add button.

  9. Figure 3 will then appear. Proceed to download the eG mobile agent from the manager. For that, in the right panel of Figure 3, first click on the iOS button. Then, click on the Download button against Download eG iOS Agent.

    Downloading eG Mobile Agent for iOS

    Figure 3 : Downloading eG Mobile Agent for iOS

  10. The eG Mobile agent will be downloaded as a zipped file. Extract the contents of the zip to any location on the application host.

  11. The extracted contents will contain an eGMobileAPM.xcframework folder. Now, open your project folder in Finder and then drag the eGMobileAPM.xcframework folder into the Xcode project of the target iOS application. Xcode offers the tools you need to develop, test, and distribute apps for Apple platforms. The Xcode project contains multiple folders and files, organized systematically to manage source code, assets, configurations, and dependencies pertaining to the target application. So the first step to RUM-enabling the iOS application is to include the eG mobile agent-related files in the Xcode project.

  12. When dragging the folder, Figure 4 will appear. From the Action drop-down in Figure 4, pick the Copy files to destination option, so that the chosen folder is copied to the Xcode project. Then, click the Finish button in Figure 4.

    Copying Mobile Agent Files to Xcode Project

    Figure 4 : Copying the mobile agent-related files to the Xcode project

  13. Next, you need to copy the eG mobile agent libraries directly into your application bundle and sign it using your project's code-signing certificate. This setting is mandatory for Xcode to distribute the target application, as it now contains a third-party dynamic framework (eG mobile agent) and its libraries. This setting ensures that the application code continues to comply with Apple's security requirements and prevents immediate runtime crashes upon launch.

    For this, do the following:

    • Click your project at the top of the left Xcode navigator panel.

    • Select your main application Target from the target list and open the General tab at the top.

    • Next, scroll down to the Frameworks, Libraries, and Embedded Content section in the General settings of your project.

    • Locate the eGMobileAPM.xcframework library here.

    • Then, click the drop-down menu in the Embed column next to the library name, and select Embed & Sign (see Figure 5).

    Setting the Embed and Sign option for eG Mobile Agent Library

    Figure 5 : Setting the Embed and Sign option for the eG mobile agent library

  14. Next, proceed to set the eG mobile agent library to be cryptographically signed using your project's signing identity at the exact moment it is copied into your application bundle. Without this option checked, embedded code dependencies will retain their original developer's signature or remain completely unsigned, causing your application to crash or be rejected upon launching on a physical iOS device.

    To so sign the eG mobile agent library, do the following:

    • In the Xcode Project Navigator, select the root project file at the very top of the navigator pane.

    • Select the iOS application being monitored from the Targets section in the center editor pane.

    • Click on the Build Phases tab along the top menu bar.

    • Expand the Embed Frameworks or Copy Files phase.

    • Locate your embedded component.

    • Check the box in the Code Sign On Copy column next to that item (see Figure 6).

      Signing eG Mobile Agent Library

      Figure 6 : Signing the eG mobile agent library using the project's signing identity

  15. By default, Xcode is configured to capture and display crash logs. However, to ease troubleshooting, you need to make sure that Xcode also captures stack traces on crashes. For that, do the following:

    • Open your XCode project.

    • Go to Product > Scheme > Edit Scheme…

    • In the left panel, select Run under the Debug configuration.

    • Under the Info tab, locate the Debug executable checkbox.

    • Uncheck the Debug executable option.

      Unchecking Debug Executable

      Figure 7 : Unchecking Debug Executable

  16. Next, you need to import the eG mobile agent into your application code. This way, your code will be able to use the eG mobile agent's classes, functions, and variables. To import, do the following:

    • Edit your application's AppDelegate.swift file. In a native iOS application built using Xcode, this file will reside in the [YourProjectName]/[YourProjectName]/ folder on the application host.

    • At the top of the file, include the following command:

      import eGMobileAPM

  17. Next, proceed to initialize the eG mobile agent. For that, follow the steps below:

    • Login to the eG administrative interface, and follow the Admin -> Infrastructure -> Add/Modify menu sequence.

    • Select Mobile RUM as the Component type in the page that appears. All managed mobile RUM components will be displayed.

    • In the list, locate the component that you added for the target iOS application and click the Modify button corresponding to it.
    • In the page that appears next, click iOS in the right panel. Figure 8 will then appear. Click on the Copy button alongside Swift (as indicated by Figure 8) to copy the eG code snippet to be injected into the target application's code.

      Copying the Swift Code Snippet

      Figure 8 : Copying the Swift code from the eG administrative interface

    • Next, edit your application's AppDelegate.swift file.
    • In the file, search for the application(_:didFinishLaunchingWithOptions:) method.
    • Paste the eG code snippet you copied earlier as the first line under the (_:didFinishLaunchingWithOptions:) method (see Figure 9).

      Injecting Code Snippet in Swift App

      Figure 9 : Injecting eG code snippet in the AppDelegate.swift file

    • Finally, save the file.

  18. Then, clean the project, build it, and run the application to ensure everything is set up correctly.

Installing and Configuring the eG Mobile Agent for an iOS Application Built Using Objective-C

For this, follow the steps below:

  1. Login to the application host.

  2. Then, open the browser, connect to the eG management console, and then login to the eG administrative interface.

  3. Follow the Infrastructure -> Add /Modify menu sequence. Figure 10 will appear. In Figure 10, pick Mobile RUM as the Component type, and click the Add New Component button to add a new Mobile RUM component.

    Selecting Mobile RUM as the Component type

    Figure 10 : Selecting Mobile RUM as the Component type

  4. Figure 11 will then appear. Provide a Nick name for the iOS application you want to monitor.

    Managing iOS App A a Mobile RUM Component

    Figure 11 : Adding the target iOS application as a Mobile RUM component

  5. Then, select the Mobile RUM collector to which the eG Mobile Agent should send the performance metrics it gathers from the target application.

  6. Next, assign a Remote agent to the Mobile RUM component. This is the agent that will pull metrics from the Mobile RUM collector and reports the same to the eG manager.

  7. To install the eG mobile agent on iOS, set Application type as Native.

  8. Finally, click the Add button.

  9. Figure 12 will then appear. Proceed to download the eG mobile agent from the manager. For that, in the right panel of Figure 12, first click on the iOS button. Then, click on the Download button against Download eG iOS Agent.

    Downloading eG Mobile Agent for iOS

    Figure 12 : Downloading eG Mobile Agent for iOS

  10. The eG Mobile agent will be downloaded as a zipped file. Extract the contents of the zip to any location on the application host.

  11. The extracted contents will contain an eGMobileAPM.xcframework folder. Now, open your project folder in the Xcode Navigator Pane and then drag the eGMobileAPM.xcframework folder into the Xcode project of the target iOS application. Xcode offers the tools you need to develop, test, and distribute apps for Apple platforms. The Xcode project contains multiple folders and files, organized systematically to manage source code, assets, configurations, and dependencies pertaining to the target application. So the first step to RUM-enabling the iOS application is to include the eG mobile agent-related files in the Xcode project.

  12. When dragging the folder, Figure 13 will appear. From the Action drop-down in Figure 13, pick the Copy files to destination option, so that the chosen folder is copied to the Xcode project. Then, click the Finish button in Figure 13.

    Copying eG mobile agent files to Xcode Project

    Figure 13 : Copying the mobile agent-related files to the Xcode project

  13. Next, you need to copy the eG mobile agent libraries directly into your application bundle and sign it using your project's code-signing certificate. This setting is mandatory for Xcode to distribute the target application, as it now contains a third-party dynamic framework (eG mobile agent ) and its libraries. This setting ensures that the application code continues to comply with Apple's security requirements and prevents immediate runtime crashes upon launch.

    For this, do the following:

    • Click your project at the top of the left Xcode navigator panel.

    • Select your main application Target from the target list and open the General tab at the top.

    • Next, scroll down to the Frameworks, Libraries, and Embedded Content section in the General settings of your project.

    • Locate the eGMobileAPM.xcframework library here.

    • Next, click the drop-down menu in the Embed column next to the library name, and select Embed & Sign (see Figure 14).

    Setting Embed and Sign Option

    Figure 14 : Setting the Embed and Sign option for the eG mobile agent library

  14. Next, proceed to set the eG mobile agent library to be cryptographically signed using your project's signing identity at the exact moment it is copied into your application bundle. Without this option checked, embedded code dependencies will retain their original developer's signature or remain completely unsigned, causing your application to crash or be rejected upon launching on a physical iOS device.

    To so sign the eG mobile agent library, do the following:

    • In the Xcode Project Navigator, select the root project file at the very top of the navigator pane.

    • Select the iOS application being monitored from the Targets section in the center editor pane.

    • Click on the Build Phases tab along the top menu bar.

    • Expand the Embed Frameworks or Copy Files phase.

    • Locate your embedded component.

    • Check the box in the Code Sign On Copy column next to that item (see Figure 15).

      Signing eG Mobile Agent Library

      Figure 15 : Signing the eG mobile agent library using the project's signing identity

  15. By default, Xcode is configured to capture and display crash logs. However, to ease troubleshooting, you need to make sure that Xcode also captures stack traces on crashes. For that, do the following:

    • Open your XCode project.

    • Go to Product > Scheme > Edit Scheme…

    • In the left panel, select Run under the Debug configuration.

    • Under the Info tab, locate the Debug executable checkbox.

    • Uncheck the Debug executable option.

      Uncheck Debug Executable

      Figure 16 : Unchecking Debug Executable

  16. Next, you need to import the eG mobile agent into your application code. This way, your code will be able to use the eG mobile agent's classes, functions, and variables. To import, do the following:

    • Edit your application's AppDelegate.m file. In a native iOS application, this file will reside inside the root project folder or the primary app target folder directly inside your project directory.

    • At the top of the file (outside of any implementation blocks), include the following statement:

      #import <eGMobileAPM/eGMobileAPM.h>

  17. Next, proceed to initialize the eG mobile agent. For that, follow the steps below:

    • Login to the eG administrative interface, and follow the Admin -> Infrastructure -> Add/Modify menu sequence.

    • Select Mobile RUM as the Component type in the page that appears. All managed mobile RUM components will be displayed.

    • In the list, locate the component that you added for the target iOS application and click the Modify button corresponding to it.
    • In the page that appears next, click iOS in the right panel. Figure 8 will then appear. Click on the Copy button alongside Objective-C (as indicated by Figure 17) to copy the eG code snippet to be injected into the target application's code.

      Copying Objective-C Code Snippet

      Figure 17 : Copying the Objective C code from the eG administrative interface

    • Next, edit your application's AppDelegate.m file.
    • In the file, search for the application:didFinishLaunchingWithOptions: method.
    • Paste the eG code snippet you copied earlier as the first line under the application:didFinishLaunchingWithOptions: method (see Figure 18).

      Figure 18 : Injecting eG Objective C code snippet in the AppDelegate.m file

    • Finally, save the file.

  18. Then, clean the project, build it, and run the application to ensure everything is set up correctly.

Troubleshooting

  1. My iOS application stopped reporting data after installing the eG mobile agent. What do I do?

    Typically, once the target mobile application starts receiving requests, data should appear in the Mobile RUM Dashboard in the eG monitoring console after the polling interval. If no data appears, follow the steps below:

    • Check the AppDelegate file and make sure you are calling the eG mobile agent in the first line of the didFinishLaunchingWithOptions() method.

    • Next, ensure that you are running the eG mobile agent on the main thread.

      Avoid calling the didFinishLaunchingWithOptions() method after the eG mobile agent, asynchronously, or in a background thread. This is because, such practices can cause unexpected or unstable behavior.

    • Then, verify if all the installation steps for the eG mobile agent have been completed and are correct.

    • If the eG mobile agent has been installed, configured, and called correctly, but the problem still persists, then check the eG log files. It is recommended that you edit the AppDelegate file to increase the eG logging level. For that, add the following line to the file before calling the startWithApplicationToken() method:

      eGLogger.setLogLevels(eGLogLevel.debug.rawValue)

      Note:

      If, after generating a few minutes of activity in the target mobile app, you notice that the eG logger is increasing performance overheads, you can comment out the line mentioned above in the AppDelegate file.