> ## Documentation Index
> Fetch the complete documentation index at: https://mw-docs.middleware.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Mobile RUM - iOS SDK

> iOS RUM - Setup & Installation Docs | Middleware

The Mobile RUM SDK provides a customizable suite of tools to analyze and optimize the performance of iOS applications. Isolate ANR and network changes, quickly detect application crashes, identify slow or frozen frames and more.

<Note> To see an example of how to deploy the Mobile RUM iOS SDK, navigate to our GitHub repository [here](https://github.com/middleware-labs/middleware-ios).</Note>

# Prerequisites

`iOS version 13`, `macOS version 10_15`, and `tvOS version 13` or above. Check your iOS SDK version with the following command:

```shell Shell theme={null}
xcodebuild -showsdks
```

# Install & Instrument Your iOS Application

### Step 1: Install Swift Package

Add the following line in `Package.swift` in `dependencies`

```swift Package.swift theme={null}
.package(url: "https://github.com/middleware-labs/middleware-ios", from: "1.0.0"),
```

### Step 2: Initialize Middleware iOS SDK

```swift swift theme={null}
import SwiftUI
import MiddlewareRum
            
@main
struct YourApp: App {
    init() {
        do {
            try MiddlewareRumBuilder()
                .globalAttributes(["customerId" : "123456"])
                .target("<target>")
                .serviceName("Mobile-SDK-iOS")
                .rumAccessToken("<account-key>")
                .deploymentEnvironment("PROD")
                .build()
        } catch {
            print("Failed to initialize \(error)")
        }
        
    }
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}  
```

# Custom Configurations

### Logs

Create Custom logs using the Middleware API

```swift swift theme={null}
MiddlewareRum.info("Some information")
MiddlewareRum.debug("Some information")
MiddlewareRum.trace("Some information")
MiddlewareRum.warning("Some information")
MiddlewareRum.error("Some information")
MiddlewareRum.critical("Some information")
```

### Errors to Traces

Create Custom logs using the Middleware API

```swift swift theme={null}
MiddlewareRum.addError("Error, unable to process")
```

### Exceptions

Create Custom exceptions using the Middleware API

```swift swift theme={null}
MiddlewareRum.addException(e: NSException(name: NSExceptionName(rawValue: "RuntimeException"), reason: "I am custom exception"))
```

### Set Your Screen Name

```swift swift theme={null}
MiddlewareRum.setScreenName("WebView")
```

### Set Global Attributes

```swift swift theme={null}
MiddlewareRum.setGlobalAttributes(["some": "value"])
```

### WebView Instrumentation

Use WebView to run native iOS apps

```swift swift theme={null}
MiddlewareRum.integrateWebViewWithBrowserRum(view: webView)
```

### Session Recording

The maximum session recording duration is four hours. If users are inactive for more than 15 minutes at a time, session recordings will be stopped. If users exceed more than four hours in a single session or become active again after the 15-minute inactivity timeout, a new session will be automatically created.

Session recording is enabled by default. Disable this feature by passing `.disableRecording()` in the following function:

```swift Swift theme={null}
MiddlewareRumBuilder()
    .globalAttributes(["customerId" : "123456"])
    .target("<target>")
    .serviceName("Mobile-SDK-iOS")
    .projectName("Mobile-SDK-iOS")
    .rumAccessToken("<account-key>")
    .deploymentEnvironment("PROD")
    .disableRecording()
    .build()
```

### Privacy

Blur sensitive information in session recordings by embedding the following method:

<Note> User passwords are automatically masked by default. Other sensitive information like credit card data and API keys must be masked manually. </Note>

```swift Swift theme={null}
// SwiftUI
Text("Very important sensitive text").sensitive()

// UIKit
MiddlewareRum.addIgnoredView(view)
```

# Instrumentation Attributes

The following methods can be used for instrumenting & configuring your application.

|                                            |                                                                                                                |
| :----------------------------------------- | :------------------------------------------------------------------------------------------------------------- |
| **Method**                                 | **Description**                                                                                                |
| `.rumAccessToken(String)`                  | Sets RUM account access token to authorize client to send telemetry to Middleware                              |
| `.target(String)`                          | Sets target URL to the location you will send telemetry data to(e.g. [Middleware](https://app.middleware.io/)) |
| `.serviceName(String)`                     | Sets service name for your application                                                                         |
| `.deploymentEnvironment(String)`           | Sets environment attribute on spans generated by instrumentation(e.g. `PROD` & `DEV`)                          |
| `.disableCrashReportingInstrumentation()`  | Disable crash reporting (which is enabled by default)                                                          |
| `.disableNetworkMonitoring()`              | Disable HTTP Instrumentation (which is enabled by default)                                                     |
| `.disableSlowRenderingDetection()`         | Disable slow/frozen frame renders (which is enabled by default)                                                |
| `.slowFrameDetectionThresholdMs(Double)`   | Sets default polling for slow render detection. Default value is `16.7` milliseconds                           |
| `.frozenFrameDetectionThresholdMs(Double)` | Sets default polling for frozen render detection. Default value is `700` milliseconds                          |

<Note> Need assistance or want to learn more about Middleware? Contact us at support\[at]middleware.io. </Note>
