Overview

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.

What You Will Create

In this codelab, you will create an app that can integrate the Crash service and manually trigger a crash to test the Crash service.

What You Will Learn

Development Environment and Skill Requirements

Device Requirements

An iPhone or a simulator for testing

To integrate the Crash service of AppGallery Connect, you must complete the following preparations:

For details, please refer to Integration Preparations.
  1. Sign in to AppGallery Connect, click My projects, click your project card, and select an app for which you want to enable the Crash service from the drop-down list on the top.
  2. Go to Quality > Crash. If you use the Crash service for the first time, click Enable now to enable HUAWEI Analytics first.

You need to integrate the Crash service SDK into your Xcode project with CocoaPods.

  1. Sign in to AppGallery Connect and click My projects.
  2. Click your project card and select an app for SDK integration from the app drop-down list on the top.
  3. Go to Project settings > General information. In the App information area, download the agconnect-services.plist file.
  4. Copy the agconnect-services.plist file to your project.
  5. 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
  6. Add the pod ‘AGConnectCrash' dependency to the Podfile.
    target 'AGC-Crash-1' do pod 'AGConnectCrash' end
  7. Install the pod and open the .xcworkspace file to view the project.
    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.

Sample code:

override func viewDidLoad() { super.viewDidLoad() let crashButton = UIButton(frame: CGRect(x: 50, y: 80, width: 120, height: 50)) crashButton.backgroundColor = UIColor.blue crashButton.setTitle("Make Crash", for: .normal) crashButton.addTarget(self, action: #selector(makeCrash), for: .touchUpInside) self.view.addSubview(crashButton) }
  1. Import AGConnectCore to the AppDelegate class of the app, and call AGCInstance.startUp in the didFinishLaunchingWithOptions method for initialization.
    import AGConnectCore func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { AGCInstance.startUp() }
  2. Call the makeCrash method to make a crash.
    @objc func makeCrash() { AGCCrash.sharedInstance().testIt() }
  1. Start Xcode and click the run button to run your app on a mobile phone or simulator.
  2. The crash data collection function is not enabled in debugging mode in Xcode. Therefore, before testing the crash data collection function of your app, stop debugging in Xcode, open the app, and tap Make Crash.
  3. After a crash occurs, ensure that the network connection is normal, restart the app, and view crash information in AppGallery Connect.
  1. Sign in to AppGallery Connect, click My projects, click your project card, and select an app.
  2. On the Crash service page, click the Statistics tab to view the crash statistics of your app.
  3. If crash data was reported, click the Issues tab and find the crash issue of your app. For example, in the following figure, NSRangeException is the issue triggered during the test.
  4. Click the issue name to see the details. On the Stack tab page, you can view the details for troubleshooting.

You have successfully created an app integrated with the Crash service of AppGallery Connect and learned how to view and analyze crashes and make different types of crashes and view crash information in AppGallery Connect.

API Reference

Sample code

Code copied