Integrating AppGallery Connect Crash Service in a Xamarin app for iOS - Huawei Developers

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.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Create a project in AppGallery Connect and enable HUAWEI Analytics.
Right-click your project and choose Manage NuGet Packages.
Find the Huawei.Agconnect.iOS.Crash package and install it.
Find the Huawei.Agconnect.iOS.AgconnectCore package, select the 1.2.0.300 version, and install it.
Add the plist file from your AppGallery Project to the project directory.
Set Build Action to BundleResource.
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
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:
Code:
using System;
using UIKit;
using Huawei.Agconnect.Crash;
using Foundation;
namespace crashios0512
{
public partial class ViewController : UIViewController
{
public ViewController(IntPtr handle) : base(handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
// You can configure additional functions as required.
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
// Delete the cached data or images that are no longer used.
}
partial void MakeCrash(UIKit.UIButton sender)
{
AGCCrash.GetSharedInstance().TestIt();
}
partial void CatchException(UIKit.UIButton sender)
{
AGCCrash.GetSharedInstance().RecordError(new Foundation.NSError());
}
partial void CustomReport(UIKit.UIButton sender)
{
AGCCrash.GetSharedInstance().SetUserId("testuser");
AGCCrash.GetSharedInstance().Log("default info level");
AGCCrash.GetSharedInstance().SetCustomValue(new NSString("test"), "this is string value");
AGCCrash.GetSharedInstance().LogWithLevel(AGCCrashLogLevel.Warning, "this is warning log level");
AGCCrash.GetSharedInstance().SetCustomValue(new NSNumber(123), "this is number");
}
}
}
View Crash Report​Tap MakeCrash, CatchException, and CustomReport in sequence, and check the report in AppGallery Connect.
View the crash statistics.
Check the exceptions
Diagnose the causes of exceptions.
Check the custom key-value pairs.
View the custom log levels
View custom user IDs.
For details, please refer to:
Crash for iOS
Codelab of Crash for iOS

Will it works on offline?

will its benefit for us or not? Epoxy Flooring Atlanta

Related

How to Integrate Image Kit's Smart Layout Service

Overview
HUAWEI Image Kit's smart layout service currently offers nine different smart layout styles, and two content layout types, which users are free to choose from.
Application Scenarios
When typesetting is performed for a digital magazine, for instance, many elements need to be incorporated onto the page, along with the text. Image Kit's smart layout service enables you to typeset with remarkable ease, and craft vivid designs, to enjoy greatly enhanced efficiency with eye-catching imagery that attracts users.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Development Practice
Now, let's take a look at how to integrate Image Kit's smart layout service.
Preparations
You'll need to add your images and configure related parameters during this process.
1. Import the smart layout service packages.
Code:
import com.huawei.hms.image.vision.bean.ImageLayoutInfo ;
import com.huawei.hms.image.vision.*;
2. Obtain an instance for the smart layout service.
Code:
// Obtain an ImageVisionImpl instance.
ImageVisionImpl imageVisionAPI = ImageVision.getInstance(this);
3. Initialize the service, which is the same as that for the filter service. For details, please refer to Development Procedure.
4. Construct parameter objects.
More detail about this, please check https://forums.developer.huawei.com/forumPortal/en/topic/0204411709476790211
For details about authJson parameters, please refer to Description of authJson parameters
Example requestJson parameter configuration:
Code:
{
"requestId":"requestId",
"taskJson":{"title":"Little luxury for the new gen","description":"Away from hustle and bustle","copyRight":"HUAWEIScreenMagazine","isNeedMask":false,"anchor":"More","styleList":["info1"]}, "authJson":{"projectId":"projectIdTest","appId":"appIdTest","authApiKey":"authApiKeyTest","clientSecret":"CSecretTest","clientId":"CIdTest","token":"tokenTest"}
}
5. Obtain the service result.
When calling the smart layout API, you'll need to specify the bitmap of the image to be processed, and select the style and text to be added (parameters). For details, please refer to step 4. The smart layout service requires a network connection. If no network connection is available, the info3 style is returned by default. The layout style is returned through ImageLayoutInfo. The smart layout service draws a view based on the style contained in ImageLayoutInfo. For more detailed operations, please refer to Sample Code. Because network requests are sent over the API, you'll need to call the API in a subthread.
Code:
//Obtain the return result from ImageLayoutInfo.
new Thread(new Runnable() {
@Override
public void run() {
ImageLayoutInfo imageLayoutInfo = imageVisionAPI.analyzeImageLayout(requestJson, imageBitmap);
}
}).start();
6. Stop the service.
If you do not need to use smart layout any longer, call the imageVisionAPI.stop() API to stop the service. If the returned stopCode is 0, it means that the service has been successfully stopped.
Code:
if (null != imageVisionAPI) {
int stopCode = imageVisionAPI.stop();
}
Source Code
To download the source code, please visit GitHub.

Implementing HUAWEI Out-of-App Purchases Using Deep Links

Background
A developer team wants to integrate HUAWEI Out-of-App Purchases, allowing users to purchase a product on the app details page of a game on HUAWEI AppGallery. To use this mode, they need to deep link a user to the app details page, and pass the ID of the product for purchase..
Official documentation: https://developer.huawei.com/consumer/en/doc/development/AppGallery-connect-Guides/appgallerykit-devguide-game#h1-1589804284330
Let’s see how they achieved this.
Implementation
1. Activity Configuration in the Manifest File
The team added intent-filters for an activity of their game.
<data android:scheme=”agpms” androidath=”/product/pay” android:host=”com.sxx.huawei”/>
The assembled request URL is agpms://com.sxx.huawei/product/pay.
The official documentation describes the requirements on the link.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Sample code:
2. Code Implementation of Redirection (Opening a Deep Link from Another App)
HUAWEI AppGallery should be used for the testing. However, the team had not released the game on AppGallery, and they failed to find a test environment on the AppGallery side. So they turned to another app.
Java:
Intent intent = new Intent();
intent.setAction("com.google.open02");
intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse("agpms://com.sxx.huawei/product/pay?producid=TestProduct503"));
startActivity(intent);
agpms://com.sxx.huawei/product/pay?producid=TestProduct503
Generally, the parameter following a question mark (?) is in the format of key=value&key1=value1.
Sample code:
As shown in the sample code, the only parameter set is producid.
3. Parameter Parsing After Redirection to the Payment Page
If the details page has not been opened before the redirection, the onCreate method of the app activity needs to be called to obtain the intent object for data parsing.
If the details page has already been opened before the redirection, the onNewIntent method of the app activity needs to be called to obtain the intent object for data parsing.
Sample code:
After the team obtains the product ID from the parsed data, the HMS Core SDK displays the payment page.
FAQs
What should I do if I fail to open the payment page after configuring the deep link?
Generally, this problem is caused by the inconsistency between scheme, host, and path in the assembled URL and those in the configuration. You can perform a check by referring to the official documentation.

Integrating HUAWEI Game Service Based on Cocos SDKHub - Integrating the App Update Function

After an app is launched, the app update function checks whether there is a later version available on AppGallery. If so, a pop-up is displayed, asking the user whether to update the app.
After you have integrated Cocos SDKHub, the function will use the SDK to check for app updates.
If your joint operations game is rejected for not integrating the app update function, check this post.
Before you integrate the app update function, you need to integrate Cocos SDKHub. (Reference: Integrating HUAWEI Game Service Based on Cocos SDKHub — Integrating Cocos SDKHub)
After that, here’s how you integrate the function:
1.Add the following code by referring to the official document:
JavaScript:
checkUpdate:function(){
var params = {
"showUpdateDialog": "1",
"forceUpdate": "0"
}
console.log("checkAppUpdate button pressed");
sdkhub.getUserPlugin().callFuncWithParam("checkAppUpdate",params);// Call the checkAppUpdate API.
}
2. Associate the code with a specified button and select the checkUpdate method as the tap event.
3. If you see the error information informing you that the callFuncWithParam method is not found during a simulator test, just test the packaged file on a real device.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
4. If the following information is displayed,
the function is integrated.
XML:
D/jswrapper: JS: checkAppUpdate pressed
I/updatesdk: UpdateSDK version is: 2.0.6.302 ,flavor: envrelease ,pkgName: com.cocos2d.xxx
D/HwConnectivityServiceEx: set 10323 wlan0 value false
I/NetworkKit_a: 27569-28056|null|com.huawei.hms.framework.network.grs.a|a|22|get url from sp is not empty.
I/DeviceUtil: UpdateSDK Get url from GRS_SDK Success!https://store1.hispace.hicloud.com/hwmarket/api/
I/StoreTask: UpdateSDK call store responsecode: 200
If the function passes the real-device test, the error displayed in the simulator test may be caused by compatibility failure.
For a mobile game that needs to be forcibly updated, pay attention to:
1. Select Force update when editing information for the new game version in AppGallery Connect.
(See step 8 in the official document)
2. Set forceUpdate in the input parameters to 1.
This way, you have successfully integrated the app update function.
very useful writeup
Neha J said:
very useful writeup
Click to expand...
Click to collapse
Thank you for your liking.

How Can I Quickly Integrate Remote Configuration to a Web App?

Recently, I found that Remote Configuration of AppGallery Connect now supports the web platform, which I’ve long been waiting for. Previously, it has only been supported on Android, but now it can be applied to web apps. For details about the integration demo, visit GitHub.​
Integration Steps​1. Enable the service.
a) Sign in to AppGallery Connect and create a web app.
b) Enable Remote Configuration.
c) Click New parameter and set parameters.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
2. Integrate the SDK.
a) Run the following command:
Code:
npm install –save @agconnect/remoteconfig
3. Implement the functions.
a) Obtain the local configuration parameters.
Create a local configuration map in the Vue.
Apply the local settings.
JavaScript:
export function applyDefault(map) {
return agconnect.remoteConfig().applyDefault(map);
}
b) Call the fetch API to fetch parameter values from the cloud.
JavaScript:
export async function fetch() {
return agconnect.remoteConfig().fetch().then(() => {
return Promise.resolve();
}).catch((err) => {
return Promise.reject(err);
});
}
c) Apply the parameter values to the local host immediately or upon the next launch.
1. Applying the parameter values immediately:
Call the apply API.
JavaScript:
export function apply() {
return agconnect
.remoteConfig().apply().then((res) => {
return Promise.resolve(res);
}
).catch(error => {
return Promise.reject(error);
});
}
2. Applying the parameter values upon the next launch:
Call the applyLastFetch API to apply the last fetched parameter values.
JavaScript:
// Load configurations.
export function applyLastLoad() {
return agconnect
.remoteConfig().loadLastFetched().then(async (res) => {
if (res) {
await agconnect.remoteConfig().apply(res);
}
return Promise.resolve(res);
}
).catch(error => {
return Promise.reject(error);
});
}
d) Obtain all parameter values from the local host and cloud.
Call the getMergedAll API to obtain all parameter values.
JavaScript:
export function getMergedAll() {
return agconnect.remoteConfig().getMergedAll();
}
e) Call the clearAll API to clear all parameter values.
JavaScript:
export function clearAll() {
agconnect.remoteConfig().clearAll();
}
References:
Demo:
https://github.com/AppGalleryConnect/agc-demos/tree/main/Web/agc-romoteconfig-demo-javascript
Remote Configuration Development Guide:
https://developer.huawei.com/consum...-remoteconfig-web-getstarted-0000001056501223
Well explained, Using remote config can we change UI elements.
What is the basic use of Remote Config in web?
sujith.e said:
Well explained, Using remote config can we change UI elements.
Click to expand...
Click to collapse
yes, that is convenient for developers.
ask011 said:
What is the basic use of Remote Config in web?
Click to expand...
Click to collapse
You can flexibly modify the behavior and appearance of applications by changing cloud parameter values.

Integration of Push kit in Unity based game

Introduction​
Push notifications offers a great way to increase your application’s user engagement and boost your retention rates by sending meaningful messages or by informing users about your application. These messages can be sent at any time and even if your app is not running at that time. To achieve this you need to follow steps.
Huawei Push Kit is a messaging service developed by Huawei for developers to send messages to apps on users’ device in real time. Push Kit supports two types of messages: notification messages and data messages, which we will cover both in this tutorial. You can send notifications and data messages to your users from your server using the Push Kit APIs or directly from the AppGallery Push Kit Console.
Things required
1. Unity Engine must be installed in the system.
2. Huawei phone or cloud debugging.
3. Visual Studio 2019
4. Android SDK & NDK
Steps to integrate
1. Sign In and Create or Choose a project on AppGallery Connect portal.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
2. Navigate to Project settings and download the configuration file.
3. Enable Push Kit from Manage APIs section.
4. Click Agree the Push service Agreement.
5. Select Data storage location.
6. Click Enable now Push notification.
7. Send Notification from the console.
8. Enter all the required details and click on Submit.
Game Development
1. Create a new game in Unity.
2. Now add game components and let us start game development.
3. Download HMS Unity Plugin from below site.
https://github.com/EvilMindDevs/hms-unity-plugin/releases
4. Open Unity Engine and import the downloaded HMS Plugin.
Choose Assets > Import Package> Custom Package
5. Choose Huawei > App Gallery.
6. Provide the AppId and other details from agconnect-service.json file and click configure Manifest.
7. Create Huawei Push Kit based scripts.
C#:
using UnityEngine;
namespace HuaweiHms{
public class IPushServiceListener:AndroidJavaProxy{
public IPushServiceListener():base("com.unity.hms.push.IPushService"){}
public virtual void onMessageReceived(RemoteMessage arg0) {
}
public void onMessageReceived(AndroidJavaObject arg0) {
onMessageReceived(HmsUtil.GetHmsBase<RemoteMessage>(arg0));
}
public virtual void onMessageSent(string arg0) {
}
public virtual void onNewToken(string arg0) {
}
public virtual void onSendError(string arg0, BaseException arg1) {
}
public void onSendError(string arg0, AndroidJavaObject arg1) {
onSendError(arg0,HmsUtil.GetHmsBase<BaseException>(arg1));
}
public virtual void onTokenError(BaseException arg0) {
}
public void onTokenError(AndroidJavaObject arg0) {
onTokenError(HmsUtil.GetHmsBase<BaseException>(arg0));
}
}
}
Result​
Tips and Tricks​
1. HMS plugin v1.2.0.
2. Make sure that you have installed HMS Core.
3. The Push Kit server allows a maximum of 1,000 tokens for sending messages at a time.
4. If exceed more than 1k it need to be sent batch wise.
Conclusion​
In this article, we have learnt what is push service, how to integrate in Unity based game. And also we have learnt that how to send notification from Huawei console to device.
References​
Unity Push kit

Categories

Resources