Exception Data Related Interfaces
Setting Breadcrumbs
Developers can call the 'Breadcrumb' interface at any point in the application to set markers. When the application crashes, the SDK collects the marker information in the order of code triggers and highlights it in the crash track to assist developers in understanding the code call logic during application crashes.
- Related Interface
/**
* @breadcrumb: Custom information, up to 100 characters, supports Chinese, English, numbers, underscores.
*/
+(void)leaveBreadcrumb:(NSString *)breadcrumb;
- Code Example
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOption:(NSDictionary *)launchOptions
{
// Set breadcrumb
[NBSAppAgent leaveBreadcrumb:@"didFinishLaunchingWithOptions"];
return YES;
}
Custom Information
When an application crashes, developers often need more information to collect the scene environment. They can upload additional information by calling the 'Custom Information' interface to assist in analyzing crash issues. The collected custom information will be displayed in the 'Custom Information' section on the exception detail page.
- Related Interface
/**
* This function can be called multiple times at any location, with a maximum of 10 additional pieces of information, each supporting up to 100 bytes, which are uploaded with the crash.
*/
+(void)setCustomerData:(NSString*)data forKey:(NSString*)key;
- Code Example
-(void)doSomething
{
[NBSAppAgent setCustomerData:@"value" forKey:@"key"];
...
}
Custom Errors
The 'Custom Error' interface can be used to collect developers' 'try / catch exceptions' and 'business errors' and display them in the 'Exception Analysis' → 'Errors' section of the Tingyun Platform, which can help developers collect exceptions and errors.
- Related Interface
/**
* Parameter Description:
* @message: Cannot be empty, maximum length of 1024 bytes, exceeding will truncate to the first 1024 bytes.
* @exception: Uploading an exception captures the stack when thrown. Not passing will only capture the stack at the interface call, and in multi-threading, only the stack of the thread calling the interface is captured, with a maximum stack depth of 100.
* @metaData: The value supports NSNumber, NSString, NSArray, NSDictionary types, with a maximum of 128k. If exceeded, set metadata to: "metaData":{"error":"The size of metaData is greater than the maximum limit of 128K"}
*/
+ (void)reportError:(NSString *)message withMetaData:(NSDictionary *)metaData;
+ (void)reportError:(NSString *)message withException:(NSException *)exception withMetaData:(NSDictionary *)metaData;
- Code Example
- (void)doSomething
{
...
if(success){
...
}else{
NSDictionary *dict = @{@"k1":@"v1",@"K2":@"V2"};
[NBSAppAgent reportError:@"errorMsg" withMetaData:dict];
}
...
}
- (void)doSomething
{
@try {
// ... do something that might throw an exception ...
}
@catch (NSException *exception) {
// report the error
NSDictionary *dict = @{@"k1":@"v1",@"K2":@"V2"};
[NBSAppAgent reportError:@"errorMsg" withException:exception withMetaData:dict];
}
@finally {
}
...
}
Setting Crash Type Collection
If there is no need to collect signal errors of a certain signal type, this interface can be called to ignore them, supporting the ignore of a single type and multiple types.
- Related Interface
/**
* SDK supported signals for collection:
* SIGABRT, //6
* SIGBUS, //10
* SIGFPE, //8
* SIGILL, //4
* SIGSEGV, //11
* SIGSYS, //12
* SIGTRAP, //5
* SIGKILL,//9
* @ignore Parameter supports string, NSNumber, NSArray
*/
+ (void)ignoreSomeSignalCrash:(id)ignore;
- Code Example
int main(int argc, char * argv[]) {
@autoreleasepool {
// Call before initialization
[NBSAppAgent ignoreSomeSignalCrash:@"SIGABRT"];
[NBSAppAgent startWithAppID:@"appkey" location:YES];
...
}
}
Setting Exception Callback
After using the 'Exception Callback' interface, you can obtain the exception data collected by the SDK 'crash, anr data' when a crash or anr occurs. Note: It needs to be called before the crash is uploaded or an anr occurs 'the SDK will upload the crash data after successfully connecting to the server'.
- Related Interface
/**
* @brief Set a custom callback when a crash or anr occurs
* @type The value is NBSCallBackOnCrash or NBSCallBackOnANR
*/
+ (void)setCallBack:(NBSCallBack)callback withType:(NBSCallBackType)type;
- Code Example
- (void)getExceptionInfo
{
// context is the context information of the crash or anr collected by the SDK
[NBSAppAgent setCallBack:^(NSDictionary *context) {
...
} withType:NBSCallBackOnCrash];
}
Setting to Not Collect Crashes and ANRs on Jailbroken Devices
After calling this interface, crash and anr information will no longer be collected on jailbroken devices.
- Related Interface
/**
* @brief Do not collect crash and anr data on jailbroken devices, need to be called before the SDK start
*/
+ (void)disableJailbreakExceptionDataCollection;
- Code Example
int main(int argc, char * argv[]) {
@autoreleasepool {
// Call before initialization
[NBSAppAgent disableJailbreakExceptionDataCollection];
[NBSAppAgent startWithAppID:@"appkey" location:YES];
...
}
}