Use the ARMS Real User Monitoring (RUM) iOS SDK APIs to configure monitoring, report custom data, and track network resources in your iOS apps.
Startup Configuration
Set the Endpoint
Sets the endpoint for your application. Call this method before start.
@objc
public static func setEndpoint(_ endpoint: String)
| Parameter | Description | Constraints | Failure Result |
|---|---|---|---|
| endpoint | Endpoint address | String length must be greater than 0 and less than 256 | API call fails, SDK stops |
Set the Workspace
Sets the workspace for your application. Call this method before start.
@objc
public static func setWorkspace(_ workspace: String)
| Parameter | Description | Constraints | Failure Result |
|---|---|---|---|
| workspace | Workspace address | String length must be greater than 0 and less than 256 | API call fails, SDK initialization fails |
Start the SDK
Initializes the SDK with the specified service ID.
@objc(start:)
public static func start(_ serviceId: String)
| Parameter | Description | Constraints | Failure Result |
|---|---|---|---|
| serviceId | ServiceId | A unique application ID generated by the Real User Monitoring platform | API call fails, SDK stops |
Set a Custom Device ID
Sets a custom device ID that replaces the automatically obtained one.
@objc
public static func setDeviceID(_ deviceID: String)
| Parameter | Description | Constraints | Failure Result |
|---|---|---|---|
| deviceID | Custom device ID | String length must be greater than 0 and less than 256, without special characters (only letters, digits, colons, spaces, underscores _, hyphens -, periods, and @ are supported) | API call fails, this setting is invalid |
Set a Custom App Version
Sets a custom app version that the SDK reports instead of the automatically detected one.
@objc
public static func setAppVersion(_ appVersion: String)
| Parameter | Description | Constraints | Failure Result |
|---|---|---|---|
| appVersion | Custom app version | String length must be greater than 0 and less than 64 | API call fails, this setting is invalid |
Set the App Channel
Sets a channel ID to identify the distribution channel of your application.
@objc
public static func setChannelID(_ channelID: String)
| Parameter | Description | Constraints | Failure Result |
|---|---|---|---|
| channelID | Custom channel ID | String length must be greater than 0 and less than 256 | API call fails, this setting is invalid |
Exclude Specific Classes
Adds a class name to the swizzle exclusion set so that matched classes skip automatic instrumentation. Use this method to exclude classes that you do not want to monitor or that cause compatibility issues. You can call this method multiple times. The SDK uses substring matching for class name exclusion.
This method must be called before SDK initialization. Define exclusion keywords carefully to avoid unintended class exclusions due to substring matching.
// Exclude all classes containing StoreKit2ViewController
[AlibabaCloudRUM excludeClassFromTracking:@"StoreKit2ViewController"];
// Exclude all classes containing BTDemoStoreKit2MixedBridge
[AlibabaCloudRUM excludeClassFromTracking:@"BTDemoStoreKit2MixedBridge"];
Enable or Disable Modules
Enables or disables specific data collection modules. Local configurations take precedence over remote configurations. Multiple calls accumulate.
This method must be called before SDK initialization. Local configurations take precedence over remote configurations. Use with caution.
@objc(disableModule:)
public static func disableModule(_ module: AlibabaCloudModule)
@objc(enableModule:)
public static func enableModule(_ module: AlibabaCloudModule)
@objc(AlibabaCloudModule)
public enum AlibabaCloudModule: Int {
case crash = 0
case network = 1
case view = 2
case action = 3
case webView = 4
case longTask = 5
case appLaunch = 6
case appState = 7
case netState = 8
case customEvent = 9
case customLog = 10
case customMetric = 11
}
| Parameter | Description | Constraints | Failure Result |
|---|---|---|---|
| module | Collection module to enable or disable | Must be of AlibabaCloudModule type | This setting is invalid |
Example:
// Disable the network data collection module
[AlibabaCloudRUM disableModule:AlibabaCloudModuleNetwork];
Set the Application Environment
Specifies the application environment, such as LOCAL, DAILY, or PROD.
@objc
public static func setEnvironment(_ env: Env)
| Parameter | Description | Constraints | Failure Result |
|---|---|---|---|
| env | Environment enum value. Must be called before the start method | Env enum, default is PROD: LOCAL, DAILY, PRE, GRAY, PROD, NONE | API call fails, this setting is invalid |
Resource Snapshot Collection
Collects HTTP request and response headers and payload information. By default, resource snapshot collection is disabled. You must explicitly enable it.
Enables resource snapshot collection for the HttpClient library by setting a ResourceSnapshotProvider.
void setResourceSnapshotProvider(ResourceSnapshotProvider? provider)
The SDK does not collect any headers or payload data by default. You must explicitly enable collection.
You are responsible for data anonymization. The SDK does not automatically filter any sensitive information, including but not limited to passwords and user personal information.
Custom Information
Set the Username
Sets a username to link monitoring data with actual users.
@objc
public static func setUserName(_ userID: String)
| Parameter | Description | Constraints | Failure Result |
|---|---|---|---|
| userID | Username identifier | String can be null or empty. Length must be 256 characters or fewer, without special characters (only digits, letters, colons, spaces, slashes, underscores, hyphens, periods, and @ are supported) | API call fails, this setting is invalid |
Set Custom User Extra Info
Sets additional user information to enrich user-level data analysis.
@objc(setUserExtraInfo:)
public static func setUserExtraInfo(_ extraInfo: [String: AnyObject])
| Parameter | Description | Constraints | Failure Result |
|---|---|---|---|
| extraInfo | User extra information | Map can be null or empty. JSON representation must be 7,000 characters or fewer | API call fails, this setting is invalid |
Set Global Properties
Sets custom global business properties. Once set, all new data automatically inherits these properties, enabling correlation between monitoring data and business attributes.
@objc(setExtraInfo:)
public static func setExtraInfo(_ extraInfo: [String: AnyObject])
@objc(addExtraInfo:)
public static func addExtraInfo(_ extraInfo: [String: AnyObject])
Calling setExtraInfo clears previously set properties. To append new properties, use addExtraInfo instead.
Report Custom Exceptions
Reports custom exception data for statistical analysis.
@objc(setCustomException:causeBy:errorDump:)
public static func setCustomException(_ exceptionType: String, causeBy: String, errorDump: String)
| Parameter | Description | Constraints | Failure Result |
|---|---|---|---|
| exceptionType | Exception type (required) | String length must be greater than 0 and 256 characters or fewer | API call fails, this setting is invalid |
| causeBy | Exception cause | String can be nil or empty. Length must be 512 characters or fewer; excess is truncated | - |
| errorDump | Exception details | String can be nil or empty. Length must be 10,000 characters or fewer; excess is truncated | - |
Report Custom Events
Reports custom event data for statistical analysis.
Multiple overloaded versions are available for different reporting requirements:
| Method Signature | Additional Parameters | Constraints |
|---|---|---|
setCustomEvent(_ name: String) |
None | name: String length must be greater than 0 and 256 characters or fewer |
setCustomEvent(_ name: String, group: String?) |
group: Event group | group: String must be 256 characters or fewer; excess is truncated |
setCustomEvent(_ name: String, group: String?, snapshots: String?) |
group, snapshots: Event snapshot | snapshots: String must be 7,000 characters or fewer; excess is truncated |
setCustomEvent(_ name: String, group: String?, value: Double) |
group, value: Event value | value: Double type |
setCustomEvent(_ name: String, group: String?, info: [String: String]?) |
group, info: Event additional information | info: JSON representation must be 7,000 characters or fewer |
setCustomEvent(_ name: String, group: String?, snapshots: String?, value: Double) |
group, snapshots, value | Constraints as described above |
setCustomEvent(_ name: String, group: String?, snapshots: String?, info: [String: String]?) |
group, snapshots, info | Constraints as described above |
setCustomEvent(_ name: String, group: String?, value: Double, info: [String: String]?) |
group, value, info | Constraints as described above |
setCustomEvent(_ name: String, group: String?, snapshots: String?, value: Double, info: [String: String]?) |
group, snapshots, value, info (full-parameter version) | Constraints as described above |
Report Custom Logs
Reports custom log information for statistical analysis.
| Method Signature | Additional Parameters | Constraints |
|---|---|---|
setCustomLog(_ logInfo: String) |
None | logInfo: String length must be greater than 0 and 10,000 characters or fewer; excess is truncated |
setCustomLog(_ logInfo: String, name: String?) |
name: Log name | name: String length must be greater than 0 and 256 characters or fewer |
setCustomLog(_ logInfo: String, name: String?, snapshots: String?) |
name, snapshots: Log snapshot | snapshots: String must be 7,000 characters or fewer; excess is truncated |
setCustomLog(_ logInfo: String, name: String?, snapshots: String?, level: String?, info: [String: String]?) |
name, snapshots, level: Log level (default: INFO), info: Log additional information | info: JSON representation shares length limit with logInfo; otherwise API call fails |
Report Custom Resources
Reports custom network resource request data, including request status, performance metrics, and trace tracking information. Two overloaded versions are available for basic and advanced scenarios.
Basic Scenario
@objc(setCustomResource:success:url:method:statusCode:errorMessage:)
public static func setCustomResource(_ type: String, success: Bool, url: String, method: String, statusCode: Int, errorMessage: String?) -> Bool
| Parameter | Type | Description | Constraints |
|---|---|---|---|
| type | String | Resource type, such as "js", "media", "api" | String length must be greater than 0 and 64 characters or fewer; excess is truncated |
| success | Bool | Whether the request was successful | true for success, false for failure |
| url | String | Full request URL | String length must be greater than 0 and 1,024 characters or fewer; excess is truncated |
| method | String | HTTP request method, such as "GET", "POST", "PUT", "DELETE" | String length must be greater than 0 and 24 characters or fewer; excess is truncated |
| statusCode | Int | HTTP response status code | HTTP status code, such as 200, 404, 500 |
| errorMessage | String? | Error message, only filled when the request fails | String length must be greater than 0 and 256 characters or fewer; excess is truncated. Can be nil |
Example:
// Swift - Successful GET request
let result = AlibabaCloudRUM.setCustomResource(
"API",
success: true,
url: "https://api.example.com/users",
method: "GET",
statusCode: 200,
errorMessage: nil
)
// Swift - Failed POST request
let result2 = AlibabaCloudRUM.setCustomResource(
"API",
success: false,
url: "https://api.example.com/login",
method: "POST",
statusCode: 401,
errorMessage: "Unauthorized access"
)
// Objective-C - Successful GET request
BOOL result = [AlibabaCloudRUM setCustomResource:@"API"
success:YES
url:@"https://api.example.com/users"
method:@"GET"
statusCode:200
errorMessage:nil];
// Objective-C - Failed POST request
BOOL result2 = [AlibabaCloudRUM setCustomResource:@"API"
success:NO
url:@"https://api.example.com/login"
method:@"POST"
statusCode:401
errorMessage:@"Unauthorized access"];
Advanced Scenario
Extends the basic version with performance metrics and trace tracking configurations.
@objc(setCustomResource:success:url:method:statusCode:errorMessage:provider:tracing:measure:)
public static func setCustomResource(_ type: String, success: Bool, url: String, method: String, statusCode: Int, errorMessage: String?, provider: String?, tracing: AlibabaCloudTracingContext?, measure: AlibabaCloudResourceMeasure?) -> Bool
In addition to the basic parameters, the advanced version supports:
provider: Service provider identifier, such as "CDN"tracing: Trace tracking context information (AlibabaCloudTracingContext)measure: Resource performance metrics (AlibabaCloudResourceMeasure)
Auxiliary Types
AlibabaCloudTracingContext
Provides context for distributed tracing. Supports W3C Trace Context and SkyWalking V3 protocols.
W3C: W3C Trace Context standard protocolSkywalkingV3: Apache SkyWalking V3 protocol
AlibabaCloudResourceMeasure
Records network request performance metrics.
| Property | Type | Description |
|---|---|---|
| duration | NSUInteger | Total time consumed (ms) |
| size | NSUInteger | Response data size (bytes) |
| connectDuration | NSUInteger | TCP connection time (ms) |
| sslDuration | NSUInteger | SSL/TLS handshake time (ms) |
| dnsDuration | NSUInteger | DNS resolution time (ms) |
| redirectDuration | NSUInteger | Redirection time (ms) |
| firstByteDuration | NSUInteger | Time to first byte (ms) |
| downloadDuration | NSUInteger | Download time (ms) |
Notes
- Check the return value: We recommend that you check the return value. If false is returned, the API call failed.
- Asynchronous reporting: A successful API call (returning true) only indicates that the SDK has accepted the data. The actual data reporting is asynchronous.