DEV Community

Zachary Powell
Zachary Powell

Posted on

Integrating AppGallery Connect Crash Service in a Xamarin app for iOS

The Huawei AppGallery Connect Crash service is a free to use crash analytics service which is supported on a wide range of platforms and frameworks.

Today lets take a look at how we can use in in a Xamarin, a hybrid framework and specifically set it up to work on iOS devices. This guide will start with a blank application but of course you can just as easily follow along and integrate into a pre-existing application!

Preparing the Xamarin Environment and Configuring Your Project

You need to install Visual Studio for MAC first, and then select Mobile development with .NET in Visual Studio to install the Xamarin environment.

Image description

Create a project in AppGallery Connect and enable HUAWEI Analytics.

Right-click your project and choose Manage NuGet Packages.
Image description
Find the Huawei.Agconnect.iOS.Crash package and install it.
Image description

Find the Huawei.Agconnect.iOS.AgconnectCore package, select the 1.2.0.300 version, and install it.
Image description

Add the plist file from your AppGallery Project to the project directory.
Image description

Set Build Action to BundleResource.
Image description

Developing Your App

Start by Configure the layout of your app for the testing of the crash service, in this example we will create three buttons to trigger different tests.
Double-click main.storyboard to launch Xcode, and create the MakeCrash, CatchException, and CustomReport buttons

Image description

In the MainActivity.cs file, call AGConnectCrash.Instance.TestIt to trigger a crash, call AGConnectCrash.Instance.SetUserId to set a custom user ID, call AGConnectCrash.Instance.SetCustomKey to set the key and value for a custom key-value pair, call AGConnectCrash.Instance.Log to set the log level, and call AGConnectCrash.Instance.RecordException to record a non-fatal exception.

This could look something like:

View Crash Report

Tap MakeCrash, CatchException, and CustomReport in sequence, and check the report in AppGallery Connect.

View the crash statistics.
Image description

Check the exceptions
Image description

Diagnose the causes of exceptions.
Image description

Check the custom key-value pairs.
Image description

View the custom log levels
Image description

View custom user IDs.
Image description

For details, please refer to:

Crash for iOS
Codelab of Crash for iOS

Top comments (0)