[Huawei Developers] Freemind R:
More information like this, you can visit HUAWEI Developer Forum​

Original link: https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201319969591990258&fid=0101187876626530001

Hello everyone,

In this article we are going to take a look at Huawei Mobile Services (HMS) integration Plugin for Unity. This article not going through the details of kits, we will focus on integration part.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805071644.03754140479737020059131834505017:50510819012907:2800:6324CE6D98ED0DA1AFD32A004BD20C5B345B4910313353B389745BF61AD7CF12.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805071644.03754140479737020059131834505017:50510819012907:2800:6324CE6D98ED0DA1AFD32A004BD20C5B345B4910313353B389745BF61AD7CF12.png[/IMG]

We will use account, In App purchases and push kit for this article. This plugin for now support five main kits.

Plugin Features :

1- Account Kit: Its provides developers with simple, secure, and quick sign-in and authorization functions. Instead of entering accounts and passwords and waiting for authorization, users can just tap the Sign In with HUAWEI ID button to quickly and securely sign in to your app. For details you read this article.

2- In App purchases: This service allows you to offer in-app purchases and facilitates in-app payment. Users can purchase a variety of virtual products, including one-time virtual products and subscriptions, directly within your app. For details you can read this article. Plugin supports the following types of products: Consumables, Non-consumables, Subscriptions

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805071729.84128145173269375298582311708074:50510819012907:2800:BECE4031C615EFD344C7CB21B82A181C8EDE1681C756B09D403AEA8B04D80072.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805071729.84128145173269375298582311708074:50510819012907:2800:BECE4031C615EFD344C7CB21B82A181C8EDE1681C756B09D403AEA8B04D80072.png[/IMG]

3- Huawei Ads: This Publisher Service utilizes Huawei’s vast user base and extensive data capabilities to deliver targeted, high quality ad content to users. With this service, your app will be able to generate revenues while bringing your users content which is relevant to them. For details you can read this article. Plugin supports the following types: Interstitial and rewarded videos

4- Push notifications: HUAWEI Push Kit is a messaging service provided by Huawei for developers. It establishes a messaging channel from the cloud to devices. By integrating HUAWEI Push Kit, developers can send messages to apps on users’ devices in real time. For details you can read this article.

5- Game kit: This kit provide player info, leaderboards and achievements.For details you can read this article.

HMS Plugin Work Flow:

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805071810.61719728534339844732711526607565:50510819012907:2800:2E8BA3B271C111B167C499289AB32C627EEA13CEE0AB539BC269E9F9BE2B8FE4.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805071810.61719728534339844732711526607565:50510819012907:2800:2E8BA3B271C111B167C499289AB32C627EEA13CEE0AB539BC269E9F9BE2B8FE4.png[/IMG]

Prerequisites

Step 1

Create an application on HUAWEI Developer(use this link for details).

Enable the HUAWEI services.

Step 2

This plugin have two branch for Unity versions.(version 2019 used)

Download plugin from this for Unity version 2019.x.

Download plugin from this for Unity version 2018.x .

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805072013.55894091853974813507330021447432:50510819012907:2800:E5894520F9958DFDBD5794A3EC0FA710C8F251B3D3FD626A5F7BD439F6CE0911.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805072013.55894091853974813507330021447432:50510819012907:2800:E5894520F9958DFDBD5794A3EC0FA710C8F251B3D3FD626A5F7BD439F6CE0911.png[/IMG]

Step 3

Import package to unity.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805072042.92791690780025664406003693798514:50510819012907:2800:6935E755FD293C625888BE5AB52A710CC9A272CD3F8FE3CFAC2D01F9D26FD2BA.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805072042.92791690780025664406003693798514:50510819012907:2800:6935E755FD293C625888BE5AB52A710CC9A272CD3F8FE3CFAC2D01F9D26FD2BA.png[/IMG]

Step 4

Update “AndroidManifest file” and “agconnect.json” file.

1- Open project_path\Assets\Plugins\Android\ AndoridManifest.

Update App ID, CP ID and package name, this informations exist in agconnect.json file.

2- Open project_path\Assets\Huawei\agconnect.json replace with you downloanded from AGC.

Integration

This plugin have some demos scenes. You can drictly use this scenes. We will create empty scene, after that we will add objects.

1. Account kit:

Create empty object and add account manager script from Huawei package component.

(Object name is important, if you want to give diffrent name from “AccountManager” update ~~\Assets\Huawei\Account\AccountManager.cs -> line 11)

Add new script “AccountSignIn” to this object.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805073445.23331808139422497808082961138565:50510819012907:2800:F61AFCC743F8D8DE3F81B9CFCB93D849BB577F56F1C2889A39F98E75412D4B11.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805073445.23331808139422497808082961138565:50510819012907:2800:F61AFCC743F8D8DE3F81B9CFCB93D849BB577F56F1C2889A39F98E75412D4B11.png[/IMG]

On AccountSignIn.cs:

using HuaweiMobileServices.Id;
using HuaweiMobileServices.Utils;
using UnityEngine;
using UnityEngine.UI;
using HmsPlugin;
public class AccountSignIn : MonoBehaviour
{
private const string NOT_LOGGED_IN = "No user logged in";
private const string LOGGED_IN = "{0} is logged in";
private const string LOGIN_ERROR = "Error or cancelled login";
private Text loggedInUser;
private AccountManager accountManager;
// Start is called before the first frame update
void Start()
{
loggedInUser = GameObject.Find("LoggedUserText").GetComponent<Text>();
loggedInUser.text = NOT_LOGGED_IN;
accountManager = AccountManager.GetInstance();
accountManager.OnSignInSuccess = OnLoginSuccess;
accountManager.OnSignInFailed = OnLoginFailure;
LogIn();
}
public void LogIn()
{
accountManager.SignIn();
}
public void LogOut()
{
accountManager.SignOut();
loggedInUser.text = NOT_LOGGED_IN;
}
public void OnLoginSuccess(AuthHuaweiId authHuaweiId)
{
loggedInUser.text = string.Format(LOGGED_IN, authHuaweiId.DisplayName);
}
public void OnLoginFailure(HMSException error)
{
loggedInUser.text = LOGIN_ERROR;
}
}

We can create sign in and sign out buttons, this buttons call “AccountSignIn” functions.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805073831.47980461716543301157413496816569:50510819012907:2800:A55498543EE3D99C9AE4FF7C287DC392D04879D961359EC0831E29FC43872177.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805073831.47980461716543301157413496816569:50510819012907:2800:A55498543EE3D99C9AE4FF7C287DC392D04879D961359EC0831E29FC43872177.png[/IMG]

2. In App purchases:

Create empty object ( Object name is important, if you want to give diffrent name from “IapManager” update ~~\Assets\Huawei\IAP\IapManager.cs -> line 11).

Add new script “IapController.cs” to this object.

Add Account kit manager to IapManager object, its needed for using IAP services.

In App Purchases have three type of product.

1- Type 0: Consumables

Description:Consumables are used once, are depleted, and can be purchased again.

Example:Extra lives and gems in a game.

Getting Consumables products from Huawei AGC with HMS Unity plugin:

public void ObtainProductConsumablesInfo(IList<string> productIdConsumablesList)
{
if (iapAvailable != true)
{
OnObtainProductInfoFailure?.Invoke(IAP_NOT_AVAILABLE);
return;
}
ProductInfoReq productInfoReq = new ProductInfoReq
{
PriceType = 0,
ProductIds = productIdConsumablesList
};
iapClient.ObtainProductInfo(productInfoReq).AddOnSuccessListener((type0) =>
{
Debug.Log("[HMSPlugin]:" + type0.ErrMsg + type0.ReturnCode.ToString());
Debug.Log("[HMSPlugin]: Found " + type0.ProductInfoList.Count + "consumable products");
OnObtainProductInfoSuccess?.Invoke(new List<ProductInfoResult> { type0});
}).AddOnFailureListener((exception) =>
{
Debug.Log("[HMSPlugin]: ERROR Consumable ObtainInfo" + exception.Message);
OnObtainProductInfoFailure?.Invoke(exception);
});
}

2- Type 1: Non-consumables

Description: Non-consumables are purchased once and do not expire.

Example:Extra game levels in a game or permanent membership of an app

3- Type 2: Subscriptions

Description:Users can purchase access to value-added functions or content in a specified period of time. The subscriptions are automatically renewed on a recurring basis until users decide to cancel.

Example:Non-permanent membership of an app, such as a monthly video membership

On IAPController.cs

# define DEBUG
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HuaweiConstants;
using HuaweiMobileServices.Base;
using HuaweiMobileServices.IAP;
using System;
using UnityEngine.Events;
using HuaweiMobileServices.Id;
using HmsPlugin;
public class IapController : MonoBehaviour
{
public string[] ConsumableProducts;
public string[] NonConsumableProducts;
public string[] SubscriptionProducts;
[HideInInspector]
public int numberOfProductsRetrieved;
List<ProductInfo> productInfoList = new List<ProductInfo>();
List<string> productPurchasedList = new List<string>();
private IapManager iapManager;
private AccountManager accountManager;
UnityEvent loadedEvent;
void Awake()
{
Debug.Log("[HMSPlugin]: IAPP manager Init");
loadedEvent = new UnityEvent();
}
// Start is called before the first frame update
/// <summary>
///
/// </summary>
void Start()
{
Debug.Log("[HMS]: Started");
accountManager = GetComponent<AccountManager>();
Debug.Log(accountManager.ToString());
accountManager.OnSignInFailed = (error) =>
{
Debug.Log($"[HMSPlugin]: SignIn failed. {error.Message}");
};
accountManager.OnSignInSuccess = SignedIn;
accountManager.SignIn();
Debug.Log("[HMS]: Started2");
}
private void SignedIn(AuthHuaweiId authHuaweiId)
{
Debug.Log("[HMS]: SignedIn");
iapManager = GetComponent<IapManager>();
iapManager.OnCheckIapAvailabilitySuccess = LoadStore;
iapManager.OnCheckIapAvailabilityFailure = (error) =>
{
Debug.Log($"[HMSPlugin]: IAP check failed. {error.Message}");
};
iapManager.CheckIapAvailability();
}
private void LoadStore()
{
Debug.Log("[HMS]: LoadStorexxx");
// Set Callback for ObtainInfoSuccess
iapManager.OnObtainProductInfoSuccess = (productInfoResultList) =>
{
Debug.Log("[HMS]: LoadStore1");
if (productInfoResultList != null)
{
Debug.Log("[HMS]: LoadStore2");
foreach (ProductInfoResult productInfoResult in productInfoResultList)
{
foreach (ProductInfo productInfo in productInfoResult.ProductInfoList)
{
productInfoList.Add(productInfo);
}
}
}
loadedEvent.Invoke();
};
// Set Callback for ObtainInfoFailure
iapManager.OnObtainProductInfoFailure = (error) =>
{
Debug.Log($"[HMSPlugin]: IAP ObtainProductInfo failed. {error.Message},,, {error.WrappedExceptionMessage},,, {error.WrappedCauseMessage}");
};
// Call ObtainProductInfo
if (!IsNullOrEmpty(ConsumableProducts))
{
iapManager.ObtainProductConsumablesInfo(new List<string>(ConsumableProducts));
}
if (!IsNullOrEmpty(NonConsumableProducts))
{
iapManager.ObtainProductNonConsumablesInfo(new List<string>(NonConsumableProducts));
}
if (!IsNullOrEmpty(SubscriptionProducts))
{
iapManager.ObtainProductSubscriptionInfo(new List<string>(SubscriptionProducts));
}
}
private void RestorePurchases()
{
iapManager.OnObtainOwnedPurchasesSuccess = (ownedPurchaseResult) =>
{
productPurchasedList = (List<string>)ownedPurchaseResult.InAppPurchaseDataList;
};
iapManager.OnObtainOwnedPurchasesFailure = (error) =>
{
Debug.Log("[HMS:] RestorePurchasesError" + error.Message);
};
iapManager.ObtainOwnedPurchases();
}
public ProductInfo GetProductInfo(string productID)
{
return productInfoList.Find(productInfo => productInfo.ProductId == productID);
}
public void showHidePanelDynamically(GameObject yourObject)
{
Debug.Log("[HMS:] showHidePanelDynamically");
var getCanvasGroup = yourObject.GetComponent<CanvasGroup>();
if (getCanvasGroup.alpha == 0)
{
getCanvasGroup.alpha = 1;
getCanvasGroup.interactable = true;
}
else
{
getCanvasGroup.alpha = 0;
getCanvasGroup.interactable = false;
}
}
public void BuyProduct(string productID)
{
iapManager.OnBuyProductSuccess = (purchaseResultInfo) =>
{
// Verify signature with purchaseResultInfo.InAppDataSignature
// If signature ok, deliver product
// Consume product purchaseResultInfo.InAppDataSignature
iapManager.ConsumePurchase(purchaseResultInfo);
};
iapManager.OnBuyProductFailure = (errorCode) =>
{
switch (errorCode)
{
case OrderStatusCode.ORDER_STATE_CANCEL:
// User cancel payment.
Debug.Log("[HMS]: User cancel payment");
break;
case OrderStatusCode.ORDER_STATE_FAILED:
Debug.Log("[HMS]: order payment failed");
break;
case OrderStatusCode.ORDER_PRODUCT_OWNED:
Debug.Log("[HMS]: Product owned");
break;
default:
Debug.Log("[HMS:] BuyProduct ERROR" + errorCode);
break;
}
};
var productInfo = productInfoList.Find(info => info.ProductId == productID);
var payload = "test";
iapManager.BuyProduct(productInfo, payload);
}
public void addListener(UnityAction action)
{
if (loadedEvent != null)
{
loadedEvent.AddListener(action);
}
}
public bool IsNullOrEmpty(Array array)
{
return (array == null || array.Length == 0);
}
}

After getting all product informations from AGC, user can buy product with “BuyProduct” function with send product ids.

Buy Product Button Settings:

Select Prefab:

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805074126.40559809341308720043984765382569:50510819012907:2800:7A3941FD5462572B6ADCBF510031C33A5472D39C7246AA2B9FDB397A43031E11.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805074126.40559809341308720043984765382569:50510819012907:2800:7A3941FD5462572B6ADCBF510031C33A5472D39C7246AA2B9FDB397A43031E11.png[/IMG]

Select Function:

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805074134.10277037656976089891782161055094:50510819012907:2800:CCDF654E8AEC3933F24EBC7002EBC18A9DB4ECFE532F8CC8D77D7C570879960F.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805074134.10277037656976089891782161055094:50510819012907:2800:CCDF654E8AEC3933F24EBC7002EBC18A9DB4ECFE532F8CC8D77D7C570879960F.png[/IMG]

Add Parameter:

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805074141.95352499425585993883450816339724:50510819012907:2800:793FC220229BCA6EF8295F6AC870FB045467DEED687311A650740CE67BBA1B9B.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805074141.95352499425585993883450816339724:50510819012907:2800:793FC220229BCA6EF8295F6AC870FB045467DEED687311A650740CE67BBA1B9B.png[/IMG]

IapManager.cs:

# define DEBUG
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HuaweiConstants;
using HuaweiMobileServices.Base;
using HuaweiMobileServices.IAP;
using System;
using UnityEngine.Events;
using HuaweiMobileServices.Id;
using HmsPlugin;
public class IapController : MonoBehaviour
{
public string[] ConsumableProducts;
public string[] NonConsumableProducts;
public string[] SubscriptionProducts;
[HideInInspector]
public int numberOfProductsRetrieved;
List<ProductInfo> productInfoList = new List<ProductInfo>();
List<string> productPurchasedList = new List<string>();
private IapManager iapManager;
private AccountManager accountManager;
UnityEvent loadedEvent;
void Awake()
{
Debug.Log("[HMSPlugin]: IAPP manager Init");
loadedEvent = new UnityEvent();
}
// Start is called before the first frame update
/// <summary>
///
/// </summary>
void Start()
{
Debug.Log("[HMS]: Started");
accountManager = GetComponent<AccountManager>();
Debug.Log(accountManager.ToString());
accountManager.OnSignInFailed = (error) =>
{
Debug.Log($"[HMSPlugin]: SignIn failed. {error.Message}");
};
accountManager.OnSignInSuccess = SignedIn;
accountManager.SignIn();
Debug.Log("[HMS]: Started2");
}
private void SignedIn(AuthHuaweiId authHuaweiId)
{
Debug.Log("[HMS]: SignedIn");
iapManager = GetComponent<IapManager>();
iapManager.OnCheckIapAvailabilitySuccess = LoadStore;
iapManager.OnCheckIapAvailabilityFailure = (error) =>
{
Debug.Log($"[HMSPlugin]: IAP check failed. {error.Message}");
};
iapManager.CheckIapAvailability();
}
private void LoadStore()
{
Debug.Log("[HMS]: LoadStorexxx");
// Set Callback for ObtainInfoSuccess
iapManager.OnObtainProductInfoSuccess = (productInfoResultList) =>
{
Debug.Log("[HMS]: LoadStore1");
if (productInfoResultList != null)
{
Debug.Log("[HMS]: LoadStore2");
foreach (ProductInfoResult productInfoResult in productInfoResultList)
{
foreach (ProductInfo productInfo in productInfoResult.ProductInfoList)
{
productInfoList.Add(productInfo);
}
}
}
loadedEvent.Invoke();
};
// Set Callback for ObtainInfoFailure
iapManager.OnObtainProductInfoFailure = (error) =>
{
Debug.Log($"[HMSPlugin]: IAP ObtainProductInfo failed. {error.Message},,, {error.WrappedExceptionMessage},,, {error.WrappedCauseMessage}");
};
// Call ObtainProductInfo
if (!IsNullOrEmpty(ConsumableProducts))
{
iapManager.ObtainProductConsumablesInfo(new List<string>(ConsumableProducts));
}
if (!IsNullOrEmpty(NonConsumableProducts))
{
iapManager.ObtainProductNonConsumablesInfo(new List<string>(NonConsumableProducts));
}
if (!IsNullOrEmpty(SubscriptionProducts))
{
iapManager.ObtainProductSubscriptionInfo(new List<string>(SubscriptionProducts));
}
}
private void RestorePurchases()
{
iapManager.OnObtainOwnedPurchasesSuccess = (ownedPurchaseResult) =>
{
productPurchasedList = (List<string>)ownedPurchaseResult.InAppPurchaseDataList;
};
iapManager.OnObtainOwnedPurchasesFailure = (error) =>
{
Debug.Log("[HMS:] RestorePurchasesError" + error.Message);
};
iapManager.ObtainOwnedPurchases();
}
public ProductInfo GetProductInfo(string productID)
{
return productInfoList.Find(productInfo => productInfo.ProductId == productID);
}
public void showHidePanelDynamically(GameObject yourObject)
{
Debug.Log("[HMS:] showHidePanelDynamically");
var getCanvasGroup = yourObject.GetComponent<CanvasGroup>();
if (getCanvasGroup.alpha == 0)
{
getCanvasGroup.alpha = 1;
getCanvasGroup.interactable = true;
}
else
{
getCanvasGroup.alpha = 0;
getCanvasGroup.interactable = false;
}
}
public void BuyProduct(string productID)
{
iapManager.OnBuyProductSuccess = (purchaseResultInfo) =>
{
// Verify signature with purchaseResultInfo.InAppDataSignature
// If signature ok, deliver product
// Consume product purchaseResultInfo.InAppDataSignature
iapManager.ConsumePurchase(purchaseResultInfo);
};
iapManager.OnBuyProductFailure = (errorCode) =>
{
switch (errorCode)
{
case OrderStatusCode.ORDER_STATE_CANCEL:
// User cancel payment.
Debug.Log("[HMS]: User cancel payment");
break;
case OrderStatusCode.ORDER_STATE_FAILED:
Debug.Log("[HMS]: order payment failed");
break;
case OrderStatusCode.ORDER_PRODUCT_OWNED:
Debug.Log("[HMS]: Product owned");
break;
default:
Debug.Log("[HMS:] BuyProduct ERROR" + errorCode);
break;
}
};
var productInfo = productInfoList.Find(info => info.ProductId == productID);
var payload = "test";
iapManager.BuyProduct(productInfo, payload);
}
public void addListener(UnityAction action)
{
if (loadedEvent != null)
{
loadedEvent.AddListener(action);
}
}
public bool IsNullOrEmpty(Array array)
{
return (array == null || array.Length == 0);
}
}

3. Push notifications:

First add your project PushKitManager prefab, this prefab using PushKitManager.cs for creating tokens.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805074517.86643939838727646876187860297661:50510819012907:2800:9AFFD6EFBAC40F1FF6193A92A78BF014EEE2188EF4D215F7D348DC564B964CBC.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805074517.86643939838727646876187860297661:50510819012907:2800:9AFFD6EFBAC40F1FF6193A92A78BF014EEE2188EF4D215F7D348DC564B964CBC.png[/IMG]

For push kit, we have a two choice,

We can send notification to all devices without token.

We can get tokens from devices and we can use this token to send notification sepicified devices.

AGC server Push Scope for sending notification:

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805074616.13313595586850764685071680866385:50510819012907:2800:57CCE16BC8C47CC08B173BC66E6B4AA3D7D7538BCE97BBB1AF5AC52EF5FDAF43.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805074616.13313595586850764685071680866385:50510819012907:2800:57CCE16BC8C47CC08B173BC66E6B4AA3D7D7538BCE97BBB1AF5AC52EF5FDAF43.png[/IMG]

On PushKitManager.cs

using HuaweiMobileServices.Base;
using HuaweiMobileServices.Id;
using HuaweiMobileServices.Push;
using HuaweiMobileServices.Utils;
using System;
using UnityEngine;
using UnityEngine.UI;

namespace HmsPlugin
{
public class PushKitManager : MonoBehaviour, IPushListener
{

public Action<string> OnTokenSuccess { get; set; }
public Action<Exception> OnTokenFailure { get; set; }

public Action<RemoteMessage> OnMessageReceivedSuccess { get; set; }

// Start is called before the first frame update
void Start()
{
PushManager.Listener = this;
var token = PushManager.Token;
Debug.Log($"[HMS] Push token from GetToken is {token}");
if (token != null)
{
OnTokenSuccess?.Invoke(token);
}
}

public void OnNewToken(string token)
{
Debug.Log($"[HMS] Push token from OnNewToken is {token}");
if (token != null)
{
OnTokenSuccess?.Invoke(token);
}
}

public void OnTokenError(Exception e)
{
Debug.Log("Error asking for Push token");
Debug.Log(e.StackTrace);
OnTokenFailure?.Invoke(e);
}

public void OnMessageReceived(RemoteMessage remoteMessage)
{
OnMessageReceivedSuccess?.Invoke(remoteMessage);
}
}
}

Push Notification result:

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805074740.36258218208760795112838069740536:50510819012907:2800:E4AA9418850E30BE1A74DFADE951CDE82936559FE7851C89A74BEAD4F7E3AFDA.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/024/888/398/5190090000024888398.20200805074740.36258218208760795112838069740536:50510819012907:2800:E4AA9418850E30BE1A74DFADE951CDE82936559FE7851C89A74BEAD4F7E3AFDA.png[/IMG]

Thank you reading this article.

I hope this gives you a starting point for Huawei Mobile Services and Unity integration.