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 service SDK can automatically collect crash data and report the data to AppGallery Connect when your app crashes, helping you understand how a specific app version performs, quickly locate the causes of crashes, and evaluate the impact of crashes.
In this codelab, you will create an app integrated with the Crash service, use custom user IDs, logs, and key-value pairs to define your crash report, and intentionally create a crash event for your app to report. In this way, you can check crash report details.
An iPhone or a simulator for testing
To integrate the Crash service of AppGallery Connect, you must complete the following preparations:
You need to integrate the Crash service SDK into your Xcode project with CocoaPods.
cd project-directory
pod init
target 'AGC-Crash-2' do
pod 'AGConnectCrash'
end
pod install
The following figure shows the result after installation.
You can create a page layout in your iOS project and design the UI according to the following figure, with a
button required for making a crash.
Sample code:
override func viewDidLoad() {
super.viewDidLoad()
let crashButton = UIButton(frame: CGRect(x: 50, y: 80, width: 160, height: 50))
crashButton.backgroundColor = UIColor.blue
crashButton.setTitle("Make Crash", for: .normal)
crashButton.addTarget(self, action: #selector(makeCrash), for: .touchUpInside)
self.view.addSubview(crashButton)
let customReportButton = UIButton(frame: CGRect(x: 50, y: 160, width: 160, height: 50))
customReportButton.backgroundColor = UIColor.blue
customReportButton.setTitle("Custom Report", for: .normal)
customReportButton.addTarget(self, action: #selector(customReport), for: .touchUpInside)
self.view.addSubview(customReportButton)
}
import AGConnectCore
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
AGCInstance.startUp()
}
@objc func makeCrash() {
AGCCrash.sharedInstance().testIt()
}
@objc func customReport() {
AGCCrash.sharedInstance().setUserId("testuser")
AGCCrash.sharedInstance().log(level: .debug, message: "set debug log")
AGCCrash.sharedInstance().log(level: .info, message: "set info log")
AGCCrash.sharedInstance().log(level: .warning, message: "set warning log")
AGCCrash.sharedInstance().log(level: .error, message: "set error log")
AGCCrash.sharedInstance().setCustomValue(value: "Hello world", key: "stringKey")
AGCCrash.sharedInstance().setCustomValue(value: false, key: "booleanKey")
AGCCrash.sharedInstance().setCustomValue(value: 1.1, key: "doubleKey")
AGCCrash.sharedInstance().setCustomValue(value: 1.1, key: "floatKey")
AGCCrash.sharedInstance().setCustomValue(value: 0, key: "intKey")
AGCCrash.sharedInstance().setCustomValue(value: 11, key: "longKey")
}
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 also create your crash report in a required form, and check it in AppGallery Connect.