This document describes the Crash Analysis API for the App Monitor iOS SDK. The API lets you create custom logs, custom dimensions, and custom exceptions.
1. Get the crash analysis instance
Obtain the EAPMCrashAnalysis instance for crash analysis. This instance is a singleton object.
API definition
+ (instancetype)crashAnalysis;class func crashAnalysis() -> SelfCode example
#import "AlicloudApmCrashAnalysis/AlicloudApmCrashAnalysis.h"
EAPMCrashAnalysis *crashAnalysis = [EAPMCrashAnalysis crashAnalysis];#import "AlicloudApmCrashAnalysis/AlicloudApmCrashAnalysis.h"
let crashAnalysis = CrashAnalysis.crashAnalysis()2. Custom logs
Crash Analytics lets you use the EAPMCrashAnalysis log interface to add custom logs. These logs are reported along with the crash information.
API definition
/**
* Records a custom log.
*
* @param msg The message to record.
*/
- (void)log:(NSString *)msg;
/**
* Records a custom log.
*
* @param format The string format.
* @param ... The parameters to replace in the format.
*/
- (void)logWithFormat:(NSString *)format, ... NS_FORMAT_FUNCTION(1, 2);/**
* Records a custom log.
*
* @param msg The message to record.
*/
func log(msg: String)Custom log parameters
Parameter | Type | Required | Length range | Description |
msg | NSString | Yes | 1 to 64,000 | The custom log message. If the message exceeds the length limit, it is truncated. |
format | NSString | Yes | 1 to 64,000 | The custom log format string. If the formatted string exceeds the length limit, it is truncated. |
Code example
#import "AlicloudApmCrashAnalysis/AlicloudApmCrashAnalysis.h"
[[EAPMCrashAnalysis crashAnalysis] log:@"custom log"];
[[EAPMCrashAnalysis crashAnalysis] logWithFormat:@"This is my custom_value=%@", @"custom_value"];#import "AlicloudApmCrashAnalysis/AlicloudApmCrashAnalysis.h"
let crashAnalysis = CrashAnalysis.crashAnalysis()
crashAnalysis.log("custom log")3. Custom exceptions
You can use the EAPMCrashAnalysis exception API to record custom exceptions. The SDK records a maximum of eight custom exceptions.
API definition
/**
* Records an exception object.
*
* @param error The exception object.
*/
- (void)recordError:(NSError *)error;
/**
* Records an exception object.
*
* @param error The exception object.
* @param userInfo Additional key-value pairs.
*/
- (void)recordError:(NSError *)error
userInfo:(nullable NSDictionary<NSString *, id> *)userInfo;/**
* Records an exception object.
*
* @param error The exception object.
*/
fun record(error: NSError)
/**
* Records an exception object.
*
* @param error The exception object.
* @param userInfo Additional key-value pairs.
*/
func record(error: NSError, userInfo: [String: Any]?)Custom exception parameters
Parameter | Type | Required | Description |
error | NSError | Yes | The exception object. |
userInfo | NSDictionary<NSString *, id> | No | Additional key-value pairs. You can add up to 64 key-value pairs. The length of each key and value cannot exceed 128 characters. |
Code example
#import "AlicloudApmCrashAnalysis/AlicloudApmCrashAnalysis.h"
NSError *error = [NSError errorWithDomain:@"customError" code:10001 userInfo:@{@"errorInfoKey":@"errorInfoValue"}];
[[EAPMCrashAnalysis crashAnalysis] recordError:error userInfo:@{
@"key1":@"value1",
@"key2":@"value2",
}];#import "AlicloudApmCrashAnalysis/AlicloudApmCrashAnalysis.h"
let crashAnalysis = CrashAnalysis.crashAnalysis()
let error = NSError(
domain: "customError",
code: 10001,
userInfo: [
"errorInfoKey": "errorInfoValue",
]
)
crashAnalysis.record(error: error, userInfo: [
"key": "value",
])