Skip to main content

Mac Platform Integration Guidelines


1 CrashSight Integration on MacOS

2 Mac SDK Integration

  1. After creating a project on the platform, the SDK that matches the platform and engine of the project can be downloaded from the "Tutorial" in the sidebar, as shown in the figure below:

  1. Drag the CrashSight.framework file into the Xcode project (Select "Copy items if needed")

2.1 SDK Initialization

2.1.1 Objective-C Initialization

  • Import header file #import <CrashSight/CrashSight.h> in the project's AppDelegate.m file

  • Initialization: Initialize in the

application:didFinishLaunchingWithOptions:

method of the project's AppDelegate.m file

CrashSightConfig* config = [[CrashSightConfig alloc] init];
// Customize the domain name for reporting (optional)
config.crashServerUrl = @"http://xxxx";
config.debugMode = true;//open debug mode
NSString* appId = @"appId";
[CrashSight startWithAppId:appId config:config];

2.1.2 Swift Initialization

  • If there is no Objective-C Bridging Header in the project, create one. · Create a new .h file · Find Build Settings->Swift Compiler-General->Objective-C Bridging Header, fill in the path of the .h file you just created
  • Import header file #import <CrashSight/CrashSight.h> in the project's Objective-C Bridging Header
  • Initialize in XXXApp.swift
@main
struct XXXApp: App {
init() {
let config = CrashSightConfig();
config.crashServerUrl = "http://xxxx";
config.debugMode = true;
let appId = "appId";
CrashSight.start(withAppId:appId,config:config);
}
...

Domain name for reporting

2.2 Integration Result Testing

After initializing CrashSight, trigger a crash by a button. A simple trigger code, such as illegal memory access, can be written to cause a crash:

int* a = NULL;
a[10000] = 5;
  • a. Enable Debug mode. Initialize CrashSight and assign suitable config parameters
  • b. Network and report: Check if “begin to upload < CSAnalyticsLogic” or “cmd: 641” is printed in the test device log
  • c. Crash detection: Check if “Handle the crash scene in callback” is printed in the test device log
  • d. Report exceptions: Check if “begin to upload < CSCrashLogic” or “cmd: 631” is printed in the test device log

3 Mac Interfaces

3.1 Initialize CrashSight with Specified Configurations

Class:CrashSight
Method:+ (void)startWithAppId:(NSString * CS_NULLABLE)appId
developmentDevice:(BOOL)development
config:(CrashSightConfig * CS_NULLABLE)config;
ParameterTypeNote
appidNSString *The appid obtained from the CrashSight backend
developmentBOOLWhether it is a development device
configCrashSightConfig *See CrashSightConfig.h header file for details

3.2 Set User ID

Class:CrashSight
Method:+ (void)setUserIdentifier:(NSString *)userId;
ParameterTypeNote
userIdNSString *User ID

3.3 Set App Version Info

Class:CrashSight
Method:+ (void)updateAppVersion:(NSString *)version;
ParameterTypeNote
versionNSString *App Version

3.4 Set Key Data, Reported with Crash Info

Note: Set the Key-Value data customized by the user. It will be reported together with exception info when sending the crash. Each key shouldn't exceed 100 characters, each value shouldn't exceed 1000 characters, and the total length (all keys+all values) shouldn't exceed 128KB.

View page: Crash Details->Download Attachments->CustomizedData.txt

Class:CrashSight
Method:+ (void)setUserValue:(NSString *)value
forKey:(NSString *)key;
ParameterTypeNote
keyNSString *Key
valueNSString *Value

3.5 Set Scene Marks

Class:CrashSight
Method:+ (void)setUserSceneTag:(NSString *)userSceneTag;
ParameterTypeNote
userSceneTagNSString *Scene Mark

3.6 Report Custom Errors

Class:CrashSight
Method:+ (void)reportExceptionWithCategory:(NSUInteger)category
name:(NSString *)aName
reason:(NSString *)aReason
callStack:(NSArray *)aStackArray
extraInfo:(NSDictionary *)info
terminateApp:(BOOL)terminate;
ParameterTypeNote
categoryNSUIntegerError type:ocoa=3,CSharp=4,JS=5,Lua=6
aNameNSString *Name
aReasonNSString *Error cause
aStackArrayNSArray *Stack
infoNSDictionary *Additional data
terminateBOOLWhether to quit application process after reporting

View page:

info: Crash Details->Download Attachments->extraMessage.txt

3.7 Set Reporting Log Level

Class:CrashSightLog
Method:+ (void)initLogger:(CrashSightLogLevel) level consolePrint:(BOOL)printConsole;
ParameterTypeNote
levelCrashSightLogLevelMinimum reporting log level
printConsoleBOOLWhether to print at the console

3.8 Custom Reporting Log

Note: Shouldn't exceed 30KB.

Class:CrashSightLog
Method:+ (void)level:(CrashSightLogLevel) level log:(NSString *)format, ... NS_FORMAT_FUNCTION(2, 3);
ParameterTypeNote
levelCrashSightLogLevelLog level
formatNSString *Log format
...Variadic parameter

3.9 Set Exception Callback

Class:CrashSightDelegate
Proxy property:delegate
Proxy protocol:CrashSightDelegate
Proxy protocol method:- (NSString * CS_NULLABLE)attachmentForException:(NSException * CS_NULLABLE)exception callbackType:(CSCallbackType)callbackType;

Note: The result returned by proxy protocol method will be reported along with the exception View page: Crash Details->Download Attachments->CrashAttach.log

callback type comparison table:

callback typeexception type
0Java crash
2Native crash
3c# exception
4ANR
5JS exception
6lua exception
8custom error