The Crash service of AppGallery Connect is a lightweight crash analysis service, in which Huawei provides a Crash SDK that can be quickly integrated into your app, without the need for coding. The SDK integrated into your app can automatically collect crash data and report the data to AppGallery Connect when your app crashes, helping you understand the version quality of your app, quickly locate the causes of crashes, and evaluate the impact scope of crashes.
In this codelab, you will create an app that can integrate the Crash service and manually trigger a crash to test the Crash service.
You can also customize your crash report to suit your service by configuring custom user IDs, recording custom logs, and defining custom key-value pairs.
To integrate the Crash service of AppGallery Connect, you must complete the following preparations:
For details, please refer to Getting Started with iOS.
The Crash service uses capabilities of HUAWEI Analytics when reporting crash events. Therefore, you must enable HUAWEI Analytics before integrating the Crash SDK. For details, please refer to Service Enabling.
If you are using Xcode, you need to integrate the Crash SDK into your Xcode project with CocoaPods.
Open the CLI and navigate to the location of the Xcode project. Then, create a Podfile. Skip this step if a Podfile already exists.
cd project-directory
pod init
target 'ioscrashdemo' do
# Pods for ioscrashdemo
pod 'HiAnalytics'
pod 'AGConnectCrash'
end
end
pod install
You can create a page in your Xcode project and design the UI according to the following figure, with two buttons required: One button is used to trigger crashes and the other is used to trigger the generation of a custom report.
In this codelab, you can test the Crash service by calling the API of the Crash SDK to create a crash and custom report, and then check whether the crash data and custom report are reported in AppGallery Connect. The procedure is as follows:
#import "AppDelegate.h"
#import <AGConnectCore/AGConnectCore.h>
#import <HiAnalytics/HiAnalytics.h>
@implementation AppDelegate
- (BOOL)Application:(UIApplication *)Application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after Application launch.
[AGCInstance startup];
[HiAnalytics config];
return YES;
}
...
@end
#import "ViewController.h"
#import <AGConnectCrash/AGConnectCrash.h>
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(100, 200, 100, 40);
[button setTitle:@"Make Crash" forState:UIControlStateNormal];
[button addTarget:self action:@selector(makecrash) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
- (void)makecrash {
[[AGCCrash sharedInstance] testIt];
}
...
@end
#import "ViewController.h"
#import <AGConnectCrash/AGConnectCrash.h>
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(100, 300, 100, 40);
[button setTitle:@"Custom Report" forState:UIControlStateNormal];
[button addTarget:self action:@selector(customreport) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
- (void) customreport {
[[AGCCrash sharedInstance] setUserId:@"iosuser"];
[[AGCCrash sharedInstance] log:@"This is default log."];
[[AGCCrash sharedInstance] logWithLevel:AGCCrashLogLevelDebug
message:@"This is debug log."];
[[AGCCrash sharedInstance] logWithLevel:AGCCrashLogLevelInfo message:@"This is info log."];
[[AGCCrash sharedInstance] logWithLevel:AGCCrashLogLevelWarning message:@"This is warning log."];
[[AGCCrash sharedInstance] logWithLevel:AGCCrashLogLevelError message:@"This is error log."];
[[AGCCrash sharedInstance] setCustomValue:@"Hello World" forKey:@"This is a World"];
[[AGCCrash sharedInstance] setCustomValue:@(1234.567) forKey:@"This is a number"];
}
...
@end
You have successfully created an app integrated with the Crash service of AppGallery Connect and learned how to view and analyze crashes and custom crash reports in AppGallery Connect. You can trigger different types of crashes and view the crashes in AppGallery Connect.
For details about APIs related to the Crash service of AppGallery Connect, please refer to API Reference.
To download the sample code, please click the button below: