HMS Crash Service (iOS – Swift)

Huawei Crash Service is a lightweight crash analysis service. You can quickly integrate crash service into your project without any coding. Crash service collects crash data and reports the data to AppGallery Connect when your app crashes.

To use Crash Service we have several steps to do.

Firstly, create a project in AppGallery Connect.

And create your app in your project.

We have to enable Analytics Kit to use Crash Service.

Go to Project Settings -> Manage APIs and enable Analytics Kit.

Go to Quality -> Crash and enable Crash Service.

Select your data storage location and currency to enable it.

After creating your project on AppGallery, we have to import configuration file. You can click here to see how to integrate Huawei SDK with using CocoaPods.

Import your agconnect-services.plist file into your Xcode project.

Adding libraries with CocoaPods

Let’s start with Crash Service integration after adding configuration file into your Xcode project.

Create a Podfile (If you don’t have).

$ cd your-project-directory
$ pod init

Edit the Podfile to add pod dependencies:

Finally, run the code below:

$ pod install

When you run pod install code, another file with .xcworkspace extension will be created. Open your project with using .xcworkspace file.

We successfully imported our configuration file and libraries to use Crash Services. And let’s continue with exploring Crash Services’ APIs.

Now open your project in Xcode. Import AGConnectCore and HiAnalytics into your AppDelegate class.

And add AGCInstance.startUp() and HiAnalytics.config() configuration methods into application function.

We added configuration methods into our AppDelegate class. And now we will add AGCCrash methods into our ViewController class.

Import AGConnectCrash into your ViewController class.

To create a crash we have a AGCCrash.sharedInstance().testIt() method. By calling it we can crash our app. On button click add this method and crash your app 🙂

We also have custom report methods such as setUserId, log, setCustomValue and so on. In this example I created a test button Custom Report in ViewController class. You can tap the button to call the setUserId method to set the user ID, the log:level method to record logs, and the setCustomValue:value method to add custom key-value pairs.

In conclusion, we covered how to integrate Huawei Crash Service into your app and use its APIs.

You can check example project here:

You can’t perform that action at this time. You signed in with another tab or window. You signed out in another tab or…

Thanks for reading 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *