Mac Platform Integration Guidelines
1 CrashSight Integration on MacOS
2 Mac SDK Integration
- 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:
- 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
- Local(China) public cloud https://mac.crashsight.qq.com/pb/sync
- International public cloud https://mac.crashsight.wetest.net/pb/sync
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;
Parameter | Type | Note |
---|---|---|
appid | NSString * | The appid obtained from the CrashSight backend |
development | BOOL | Whether it is a development device |
config | CrashSightConfig * | See CrashSightConfig.h header file for details |
3.2 Set User ID
Class:CrashSight
Method:+ (void)setUserIdentifier:(NSString *)userId;
Parameter | Type | Note |
---|---|---|
userId | NSString * | User ID |
3.3 Set App Version Info
Class:CrashSight
Method:+ (void)updateAppVersion:(NSString *)version;
Parameter | Type | Note |
---|---|---|
version | NSString * | 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;
Parameter | Type | Note |
---|---|---|
key | NSString * | Key |
value | NSString * | Value |
3.5 Set Scene Marks
Class:CrashSight
Method:+ (void)setUserSceneTag:(NSString *)userSceneTag;
Parameter | Type | Note |
---|---|---|
userSceneTag | NSString * | 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;
Parameter | Type | Note |
---|---|---|
category | NSUInteger | Error type:ocoa=3,CSharp=4,JS=5,Lua=6 |
aName | NSString * | Name |
aReason | NSString * | Error cause |
aStackArray | NSArray * | Stack |
info | NSDictionary * | Additional data |
terminate | BOOL | Whether 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;
Parameter | Type | Note |
---|---|---|
level | CrashSightLogLevel | Minimum reporting log level |
printConsole | BOOL | Whether 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);
Parameter | Type | Note |
---|---|---|
level | CrashSightLogLevel | Log level |
format | NSString * | 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 type | exception type |
---|---|
0 | Java crash |
2 | Native crash |
3 | c# exception |
4 | ANR |
5 | JS exception |
6 | lua exception |
8 | custom error |