This document describes the basic APIs provided by the mobile monitoring iOS SDK, including starting the SDK, updating the user ID and user nickname, getting the SDK version, and adjusting the log level.
Step 1: Start the SDK
Start the SDK with the options configuration object.
API definition
#import "AlicloudApmCore/AlicloudApmCore.h"
+ (void)startWithOptions:(EAPMOptions *)options;#import "AlicloudApmCore/AlicloudApmCore.h"
class func start(options: EAPMOptions)EAPMOptions parameters
Parameter | Type | Required | Description |
appKey | NSString | Yes | The |
appSecret | NSString | Yes | The |
appRsaSecret | NSString | Yes | The |
sdkComponents | NSArray<Class< EAPMSDKComponent>> | Yes | The service components to load with the mobile monitoring SDK. crash analysis: performance analysis: remote log: |
userId | NSString | No | The user ID. We recommend keeping this ID unique. The maximum length is 128 characters. This parameter is currently used only for crash analysis. |
userNick | NSString | No | The user nickname. The maximum length is 128 characters. |
channel | NSString | No | The channel identifier. |
Code example
#import "AlicloudApmCore/AlicloudApmCore.h"
#import "AlicloudApmCrashAnalysis/AlicloudApmCrashAnalysis.h"
#import "AlicloudApmPerformance/AlicloudApmPerformance.h"
#import "AlicloudApmRemoteLog/AlicloudApmRemoteLog.h"
EAPMOptions *options = [[EAPMOptions alloc] initWithAppKey:@"Your AppKey"
appSecret:@"Your AppSecret"];
options.appRsaSecret = @"Your AppRsaSecret";
options.sdkComponents = @[[EAPMCrashAnalysis class], [EAPMPerformance class], [EAPMRemoteLog class]];
options.userId = @"userId";
options.userNick = @"userNick";
options.channel = @"channel";
[EAPMApm startWithOptions:options];#import "AlicloudApmCore/AlicloudApmCore.h"
#import "AlicloudApmCrashAnalysis/AlicloudApmCrashAnalysis.h"
#import "AlicloudApmPerformance/AlicloudApmPerformance.h"
#import "AlicloudApmRemoteLog/AlicloudApmRemoteLog.h"
let options = EAPMOptions(
appKey: "Your AppKey",
appSecret: "Your AppSecret",
// The following sdkComponents map to crash analysis, performance analysis, and remote log. Remove any that you do not need.
sdkComponents: [CrashAnalysis.self, Performance.self, RemoteLog.self]
)
options.userId = "userId"
options.userNick = "userNick"
options.channel = "channel"
options.appRsaSecret = "Your AppRsaSecret"
EAPMApm.start(options: options)
Step 2: Update user ID
API definition
#import "AlicloudApmCore/AlicloudApmCore.h"
- (void)setUserId:(NSString *)userId;#import "AlicloudApmCore/AlicloudApmCore.h"
func setUserId(userId: String)Parameters
Parameter | Type | Required | Description |
userId | NSString | Yes | The user ID. We recommend keeping this ID unique. The maximum length is 128 characters. |
Code example
#import "AlicloudApmCore/AlicloudApmCore.h"
[[EAPMApm defaultApm] setUserId:@"userId"];#import "AlicloudApmCore/AlicloudApmCore.h"
EAPMApm.apm().setUserId("userId")Step 3: Update user nickname
API definition
#import "AlicloudApmCore/AlicloudApmCore.h"
- (void)setUserNick:(NSString *)userNick;#import "AlicloudApmCore/AlicloudApmCore.h"
func setUserNick(userNick: String)Parameters
Parameter | Type | Required | Description |
userNick | NSString | Yes | The user nickname. The maximum length is 128 characters. |
Code example
#import "AlicloudApmCore/AlicloudApmCore.h"
[[EAPMApm defaultApm] setUserNick:@"userNick"];#import "AlicloudApmCore/AlicloudApmCore.h"
EAPMApm.apm().setUserNick("userNick")Step 4: Get SDK version
API definition
#import "AlicloudApmCore/AlicloudApmCore.h"
NSString *EAPMVersion(void);#import "AlicloudApmCore/AlicloudApmCore.h"
func EAPMVersion() -> StringCode example
#import "AlicloudApmCore/AlicloudApmCore.h"
NSString *apmVersion = EAPMVersion();#import "AlicloudApmCore/AlicloudApmCore.h"
let apmVersion: String = EAPMVersion()Step 5: Adjust SDK log level
Sets or gets the SDK log level. The default is EAPMLoggerLevelNotice.
API definition
#import "AlicloudApmCore/AlicloudApmCore.h"
/**
* Sets the EAPM SDK log level.
*
* @param loggerLevel The log level. The default level is EAPMLoggerLevelNotice.
*/
- (void)setLoggerLevel:(EAPMLoggerLevel)loggerLevel;
/**
* Returns the EAPM log level.
*/
- (EAPMLoggerLevel)loggerLevel;#import "AlicloudApmCore/AlicloudApmCore.h"
/**
* Sets the EAPM SDK log level.
*
* @param loggerLevel The log level. The default level is EAPMLoggerLevelNotice.
*/
func setLoggerLevel(loggerLevel: EAPMLoggerLevel)
func EAPMSetLoggerLevelNotice()
func EAPMSetLoggerLevelWarning()
func EAPMSetLoggerLevelError()
func EAPMSetLoggerLevelDebug()
/**
* Returns the EAPM log level.
*/
func loggerLevel() -> EAPMLoggerLevelEAPMLoggerLevel enumeration
Parameter | Description |
EAPMLoggerLevelError | Error level. Indicates critical error information. |
EAPMLoggerLevelWarning | Warning level. Indicates potential issues or unexpected exceptions. |
EAPMLoggerLevelNotice | Notice level. Indicates normal but noteworthy events. |
EAPMLoggerLevelInfo | Info level. Indicates general operational information. |
EAPMLoggerLevelDebug | Debug level. Indicates detailed debug information, mainly for troubleshooting during development. |
Code example
#import "AlicloudApmCore/AlicloudApmCore.h"
// Set the log level
[EAPMConfiguration.sharedInstance setLoggerLevel:EAPMLoggerLevelDebug];
// Get the log level
EAPMLoggerLevel loggerLevel = [EAPMConfiguration.sharedInstance loggerLevel];#import "AlicloudApmCore/AlicloudApmCore.h"
// Set the log level
EAPMConfiguration.shared.setLoggerLevel(EAPMLoggerLevel.debug)
EAPMSetLoggerLevelDebug()
// Get the log level
let loggerLevel: EAPMLoggerLevel = EAPMConfiguration.shared.loggerLevel()Step 6: Custom dimensions
Use these APIs to set up to 64 custom dimensions.
API definition
/**
* Sets a key-value pair for a custom dimension.
*
* @param value The value.
* @param key The unique key.
*/
- (void)setCustomValue:(nullable id)value forKey:(NSString *)key;
/**
* Sets multiple key-value pairs for custom dimensions in a batch.
*
* @param keysAndValues The key-value pairs.
*/
- (void)setCustomKeysAndValues:(NSDictionary *)keysAndValues;/**
* Sets a key-value pair for a custom dimension.
*
* @param value The value.
* @param key The unique key.
*/
func setCustomValue(value: Any?, forKey key: String)
/**
* Sets multiple key-value pairs for custom dimensions in a batch.
*
* @param keysAndValues The key-value pairs.
*/
func setCustomKeysAndValues(keysAndValues: [String: Any])Custom dimension parameters
Parameter | Type | Required | Length range | Description |
value | id | No | 0–128 | The value for the custom dimension. The SDK converts the value to a string by calling its |
key | NSString | Yes | 1–128 | The key for the custom dimension. |
Code example
#import "AlicloudApmCore/AlicloudApmCore.h"
[[EAPMApm defaultApm] setCustomValue:@"value" forKey:@"key"];
[[EAPMApm defaultApm] setCustomKeysAndValues:@{
@"key1":@"value1",
@"key2":@"value2",
}];#import "AlicloudApmCore/AlicloudApmCore.h"
let apm = EAPMApm.defaultApm()
apm.setCustomValue("value", forKey: "key")
apm.setCustomKeysAndValues([
"key1": "value1",
"key2": "value2"
])Step 7: Get unique device ID (UTDID)
API definition
#import "AlicloudApmCore/AlicloudApmCore.h"
+ (NSString *)utdid;#import "AlicloudApmCore/AlicloudApmCore.h"
class func utdid() -> StringCode example
#import "AlicloudApmCore/AlicloudApmCore.h"
NSString *utdid = [EAPMApm utdid];#import "AlicloudApmCore/AlicloudApmCore.h"
let utdid: String = EAPMApm.utdid()