Integrating HUAWEI In-App Purchases Using Unity - Huawei Developers

Huawei's In-App Purchases (IAP) service allows you to offer in-app purchases and facilitates in-app payment. Users can purchase a variety of virtual products, including consumables and non-consumables.
1.1 Version Change History​
{
"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"
}
1.1.1 Version Dependencies​l The SDK of the latest version can be used only on devices running HMS Core (APK) 4.0.0.300 or later. If a user is using a device without HMS Core (APK) 4.0.0.300 or later, the user will be directed to install it when it is called by your app. User devices need to run EMUI 3.0 or later or Android 4.4 or later (API level 19 or later). The Unity version must be 2018.4.25 or later.
1.2 Preparations​1.2.1 Importing Unity Assets​1. Open Asset Store in Unity.
Go to Window > Asset Store in Unity.
2. Search for and import the Unity Distribution Portal (UDP) asset in Asset Store. For information about UDP, please visit https://docs.unity3d.com/Packages/[email protected]/manual/index.html.
1.2.2 App Development​Configure product information based on the sample, and then use the sample for test.
1.2.2.1 Uploading Your Project to UDP​1. Go to Window > Unity Distribution Portal > Settings in Unity and click Go to the Services Window.
2. Select an organization.
3. linked your project to a UDP client
Go to Window > Unity Distribution Portal > Settings > Inspector in Unity and click Generate new UDP client.
4. Set Game Title and UDP Sandbox Test Accounts.
1.2.2.2 Configuring Product Information in Your Unity Project​Go to Window > Unity Distribution Portal > Settings > Inspector > IAP Catalog.
After product information is configured, click Push to synchronize the information to UDP.
1.2.2.3 Creating an App and Configuring Product Information in AppGallery Connect​1.2.2.3.1 Creating an App​Create an app by following instructions in Creating an AppGallery Connect Project and Adding an App to the Project. The package name of the game for AppGalleryKit must end with .HUAWEI or .huawei. Otherwise, the game will be rejected.
1.2.2.3.2 Configuring Product Information​1. Sign in to AppGallery Connect and click My projects. Select your project, enable In-App Purchases, and obtain the public key.
2. Sign in to AppGallery Connect and click My apps.
3. Click an app from the app list to add a product.
1. Go to Operate > Products > Product Management and click Add Product.
2. Configure product information, which must be the same as that configured in Unity.
3. Activate the product.
1.2.2.4 Configuring the Unity Project Package Name​Go to Edit > Project Settings > Player, click the Android icon, and go to Other Settings.
Note: Ensure that the package name configured here must be the same as that in AppGallery Connect. All package names in AppGallery Connect must end with .huawei. If the package name in Unity does not end with .huawei, the UDP console will supplement it during repacking for name consistency.
1.2.2.5 Configuring Product Information in GameManager​1. Drag UDPSampleScene to the top.
2. Enter the configured product ID in GameManger.
3. Push all configurations.
1.2.3 Testing the APK​1. Go to File > Build Settings > Android in Unity and click Switch Platform.
1.1 Select UDP/Sample/UDPSampleScene.
1.2 Build the project. Save and install the APK.
2. Use the configured sandbox test account to initialize the APK.
2.1 Open the APK and tap Init.
2.2 Enter the configured sandbox account.
3. Initialize the sandbox test.
4. Tap the Buy button to test the product purchase function.
Verify that the sandbox test is complete.
1.2.4 Repacking the APK​1. Sign in to the UDP console.
2. Click the newly created game.
3. Edit the game information and then click Release.
4. Choose HUAWEI AppGallery.
5. Unity will automatically find the project info that has same package name in AGC, Set your IAP public Key manually
6. Choose HUAWEI AppGallery and click Publish.
7. The UDP console repacks your APK.
8. Download the repacked APK, which supports payment by IAP.
For more details, you can go to:
l Our official website
l Our Development Documentation page, to find the documents you need
l Reddit to join our developer discussion
l GitHub to download demos and sample codes
l Stack Overflow to solve any integration problems

Related

【Trip to HMS Core 5.0】Add Analytics Kit to Your iOS App

More articles like this, you can visit HUAWEI Developer Forum
​HUAWEI Analytics Kit 5.0 version has been updated, and it supports iOS SDK now, enabling one-stop, unified analysis of cross-platform Android and iOS users. It looks into user-centric analysis and helps you understand user behavior on the Android and iOS platforms. Today I want to share with you how to add Analytics Kit to your iOS App. The version I integrated is 5.0.0.300.
The general steps we will walk through include:
Configuring App Information in AppGallery Connect
Integrating the HMS Core SDK
Accessing HUAWEI Analytics Kit
Configuring App Information in AppGallery Connect
Follow the steps below to configure App Information in AppGallery Connect for your iOS application. If you have both an Android and an iOS version of your app, you can set them within the same project, this will allow you to finish the data analysis conveniently.
{
"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"
}
Getting Started:
1. Have your Bundle ID ready for your iOS app (ask your developers for this).
2. Go to AppGallery Connect and create a new project.
Once you’ve created a new project, you’ll see a page, and the side navigation bar shows the AGC's various function menus.
3. Click Add app, and create an iOS application.
Here the App package ID is the Bundle ID.
Click OK, and then you will get the configuration file agconnect-services.plist.
Click Manage APIs, and here we’ve already had the Analytics API enabled.
Back to the side navigation bar, and go to the HUAWEI Analytics tab, you will see all kinds of functions, including User analysis, Behavior analysis, etc. Select any menu to Enable Analytics service.
On the Project access settings page, set the data storage location, time zone, currency, user data storage time, and calendar week, and click Finish.
Integrating the HMS Core SDK (in Cocoapods Mode)
I prefer the Cocoapods Mode. You can also integrate the HMS Core SDK into the Xcode Project Manually.
1. Add the AppGallery Connect configuration file of the app to your XCode project.
a. Click Download agconnect-services.plist to obtain your iOS config file (agconnect-services.plist).
b. Move your agconnect-services.plist file into the root of your Xcode project.
2. Edit the Podfile file
a. Create a Podfile if you don't already have one:
$ cd your-project-directory
$ pod init
b. To your Podfile, add the pods that you want to use in your app: Add pod 'HiAnalytics', that is, the dependency for pod.
Example Podfile file:
Code:
# Uncomment the next line to define a global platform for your project
# platform :iOS, '9.0'
target 'HiAnalyticsSwiftDemo' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for HiAnalyticsSwiftDemo
pod 'HiAnalytics'
target 'HiAnalyticsSwiftDemoUITests' do
# Pods for testing
end
end
c. Install the pods, then open your .xcworkspace file to see the project in Xcode:
$ pod install
$ open your-project.xcworkspace
Accessing HUAWEI Analytics Kit
1. Initialize Analytics SDK in your app
The final step is to add initialization code to your application. Initialize AppDelegate through the config interface.
Objective C sample code: Perform initialization in AppDelegate.m.
Code:
#import "AppDelegate.h"
#import <HiAnalytics/HiAnalytics.h>
@interface AppDelegate ()
@end
@implementation AppDelegate
...
- (BOOL)Application:(UIApplication *)Application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after Application launch.
[HiAnalytics config];//Initialization
return YES;
}
...
@end
Swift code example: Perform initialization in AppDelegate.swift.
Code:
import UIKit
import HiAnalytics
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
...
func Application(_ Application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after Application launch.
HiAnalytics.config();//Initialization
return true
}
...
}
2. Record defined events using the onEvent API.
For definitions of the events, please refer to Event Description.
3. Call APIs of HUAWEI Analytics Kit to implement the corresponding functions. For details, please refer to API Reference.
During the development, you can use DebugView to view the event records in real time, observe the results, and adjust the event tracing scheme.
Enabling/Disabling the Debug Mode
1.To enable the debug mode:
Go to Product > Scheme > Edit Scheme from the Xcode menu. On the Arguments page, click + to add the -HADebugEnabled parameter. After the parameter is added, click Close to save the setting.
Code:
1. –HADebugEnabled
2.To disable the debug mode
Code:
1. -HADebugDisabled
After the data is successfully reported, you can go to HUAWEI App Debugging to view the data, as shown in the following figure.
Q&A:
1. I have integrated the iOS SDK of HUAWEI Analytics Kit into my app but why no log events are collected when the app is running?
When this problem occurs, it is probable that the run log parameters have not been set. You can set the log level to any of the following values: -HALogLevelDebug, -HALogLevelInfo, -HALogLevelWarn, and -HALogLevelError.
For example, to set the log level to -HALogLevelDebug, perform the following steps:
Choose Product > Scheme > Edit Scheme from the Xcode menu.
On the Arguments page, click + to add the -HALogLevelDebug parameter.
After the parameter is added, click Close to save the setting.
Face problems during development? Take it easy. Go to Stack Overflow and raise your questions. Huawei experts will get back to you as soon as possible.
https://stackoverflow.com/questions/tagged/huawei-mobile-services?tab=Newest

Cocos Creator Integrates with AppGallery Connect APM – Releasing a Cocos-based App

According to the introduction of Cocos Creator from its official website, Cocos Creator 2.4.1 and later versions support HUAWEI AppGallery Connect and have been providing multiple AppGallery Connect services. The following figure shows all supported AppGallery Connect services.
{
"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"
}
To test how well Cocos supports AppGallery Connect services, this article uses the App Performance Management (APM) service as an example to monitor the performance data of a Cocos-developed app. First, let's see what APM is.
AppGallery Connect APM
APM of AppGallery Connect provides minute-level app performance monitoring capabilities. You can view and analyze app performance data collected by APM in AppGallery Connect to comprehensively understand the performance features of developed apps, helping you quickly and accurately rectify possible performance problems and continuously improve user experience.
That is, APM can help you monitor your app performance data in a variety of scenarios, including app launch, page loading, and network request. We can assume that APM can quickly locate performance-related problems for games, which attach great importance to performance as it greatly affects user experience.
Before You Start
Downloading and Installing the Cocos Dashboard
1. The Cocos Dashboard is the GUI-based development tool provided by Cocos. You can download it from https://www.cocos.com/creator/ (latest version: 2.4.2).
2. You need to install the Visual Studio as well to obtain the Cocos dependency package. The following figure shows the installation procedure.
3. After the installation is complete, click Run
Downloading and Installing Cocos Creator
1. Open the Cocos Dashboard and click Signin in the upper right corner. You can sign up first if you do not have an account.
2. After sign-in, click Editor on the left, and then click Download in the lower right corner.
3. On the Editor page, select the latest version of Cocos Creator, click the download button on the right, and agree with the terms.
4. Once the download is complete, you can create a Cocos project on the Project page. Take a HelloWorld project as an example.
5. When you open the project for the first time, the system prompts you to select a language. Just select English. Select the corresponding running environment and click Run.
Configuring the Visual Studio Code Compilation Environment
The built-in code editor of Cocos is too simple and is only suitable for code viewing and a small amount of editing. Therefore, we need a more mature and powerful compilation environment. This is where Visual Studio Code comes in.
1. Download and install Visual Studio Code of the required version based on your computer environment.
2. Open your project in Cocos Creator and choose Developer > VS Code Workflow > Install VS Code Extension from the main menu to add an adaptation plug-in to Cocos Creator.
3. If the information shown in the following figure is displayed, the installation is successful.
4. If you want the system to autocomplete the Cocos Creator engine API during coding, you need to generate the API autocompletion data and put the data in the project path through the menu. Choose Developer > VS Code Workflow > Update VS Code API Source.
5. Double-click the HelloWorld.js script in the project directory. In the dialog box that is displayed, click Yes and select Visual Studio Code as the default editor.
6. Double-click the HelloWorld.js script again to develop your app.
Packaging and Releasing a Cocos-based App in AppGallery Connect
Cocos Creator 2.4.1 and later versions allow you to package and release your app to HUAWEI AppGallery through AppGallery Connect. In addition, Cocos Creator suports various AppGallery Connect services, such as APM, which can be quickly integrated and used. The detailed procedure is as follows:
1. Sign in to AppGallery Connect and create an app.
2. Sign in to Cocos Creator, choose Project > Build…, and select HUAWEI AppGallery Connect as the release platform.
3. Click Build. If Built huawei-agc successfully is displayed, the build is successful.
Note: When you build a project for the first time, you need to choose File > Settings… and configure the Android SDK path and NDK path on the native development environment page.
4. Click Compile and wait until the compilation is successful.
5. A jsb-default or jsb-link directory (depending on the template selected on the Build… panel) is generated in the build directory of the default release path. AppGallery Connect services are automatically integrated in the directory. Open the publish directory in the jsb-link directory to view the generated APK file.
6. Upload the packaged APK file locally or using AppGallery Connect.
l Uploading the file on the Upload... panel.
a) Login Type: OAuth
Click Confirm, sign in to your HUAWEI ID (with sufficient permissions), and select the check box of the corresponding permissions. The APK file will be uploaded automatically.
b) Login Type: API Client
Sign in to AppGallery Connect to obtain related configuration. Go to Users and permissions > Connect API > Create, create an API client, select a role as required, and click OK.
Enter your client ID and key of the API client in the text boxes on the Upload... panel in Cocos Creator. Click Confirm.
After the APK file is uploaded successfully, you can view it in AppGallery Connect.
Uploading the file in AppGallery Connect
Click Upload and select the APK generated by Cocos Creator.
For more details, please refer to:
Cocos official documents
AppGallery Connect APM development guide
AppGallery Connect console
GitHub to download demos and sample codes
Stack Overflow to solve any integration problems​

Cocos Creator Integrates with AppGallery Connect APM - Releasing a Cocos-based App

According to the introduction of Cocos Creator from its official website, Cocos Creator 2.4.1 and later versions support HUAWEI AppGallery Connect and have been providing multiple AppGallery Connect services. The following figure shows all supported AppGallery Connect services.
{
"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"
}
To test how well Cocos supports AppGallery Connect services, this article uses the App Performance Management (APM) service as an example to monitor the performance data of a Cocos-developed app. First, let's see what APM is.
AppGallery Connect APM
APM of AppGallery Connect provides minute-level app performance monitoring capabilities. You can view and analyze app performance data collected by APM in AppGallery Connect to comprehensively understand the performance features of developed apps, helping you quickly and accurately rectify possible performance problems and continuously improve user experience.
That is, APM can help you monitor your app performance data in a variety of scenarios, including app launch, page loading, and network request. We can assume that APM can quickly locate performance-related problems for games, which attach great importance to performance as it greatly affects user experience.
Before You Start
Downloading and Installing the Cocos Dashboard
The Cocos Dashboard is the GUI-based development tool provided by Cocos. You can download it from (latest version: 2.4.2).
2. You need to install the Visual Studio as well to obtain the Cocos dependency package. The following figure shows the installation procedure.
3. After the installation is complete, click Run
Downloading and Installing Cocos Creator
1. Open the Cocos Dashboard and click Signin in the upper right corner. You can sign up first if you do not have an account.
2. After sign-in, click Editor on the left, and then click Download in the lower right corner.
3. On the Editor page, select the latest version of Cocos Creator, click the download button on the right, and agree with the terms.
4. Once the download is complete, you can create a Cocos project on the Project page. Take a HelloWorld project as an example.
5. When you open the project for the first time, the system prompts you to select a language. Just select English. Select the corresponding running environment and click Run.
Configuring the Visual Studio Code Compilation Environment
The built-in code editor of Cocos is too simple and is only suitable for code viewing and a small amount of editing. Therefore, we need a more mature and powerful compilation environment. This is where Visual Studio Code comes in.
1. Download and install Visual Studio Code of the required version based on your computer environment.
2. Open your project in Cocos Creator and choose Developer > VS Code Workflow > Install VS Code Extension from the main menu to add an adaptation plug-in to Cocos Creator.
3. If the information shown in the following figure is displayed, the installation is successful.
4. If you want the system to autocomplete the Cocos Creator engine API during coding, you need to generate the API autocompletion data and put the data in the project path through the menu. Choose Developer >
VS Code Workflow > Update VS Code API Source.
5. Double-click the HelloWorld.js script in the project directory. In the dialog box that is displayed, click Yes and select Visual Studio Code as the default editor.
6. Double-click the HelloWorld.js script again to develop your app.
Packaging and Releasing a Cocos-based App in AppGallery Connect
Cocos Creator 2.4.1 and later versions allow you to package and release your app to HUAWEI AppGallery through AppGallery Connect. In addition, Cocos Creator suports various AppGallery Connect services, such as APM, which can be quickly integrated and used. The detailed procedure is as follows:
1. Sign in to AppGallery Connect and create an app.
2. Sign in to Cocos Creator, choose Project > Build…, and select HUAWEI AppGallery Connect as the release platform.
3. Click Build. If Built huawei-agc successfully is displayed, the build is successful.
Note: When you build a project for the first time, you need to choose File > Settings… and configure the Android SDK path and NDK path on the native development environment page.
4. Click Compile and wait until the compilation is successful.
5. A jsb-default or jsb-link directory (depending on the template selected on the Build… panel) is generated in the build directory of the default release path. AppGallery Connect services are automatically integrated in the directory. Open the publish directory in the jsb-link directory to view the generated APK file.
6. Upload the packaged APK file locally or using AppGallery Connect.
Uploading the file on the Upload… panel.
a) Login Type: OAuth
Click Confirm, sign in to your HUAWEI ID (with sufficient permissions), and select the check box of the corresponding permissions. The APK file will be uploaded automatically.
b) Login Type: API Client
Sign in to AppGallery Connect to obtain related configuration. Go to Users and permissions > Connect API > Create, create an API client, select a role as required, and click OK.
Enter your client ID and key of the API client in the text boxes on the Upload… panel in Cocos Creator. Click Confirm.
After the APK file is uploaded successfully, you can view it in AppGallery Connect.
Uploading the file in AppGallery Connect
Click Upload and select the APK generated by Cocos Creator.
great
It's very useful. Recently, our Cocos project is focusing on Huawei AppGallery.

Coding-free Integration of AppGallery Connect Crash into a Cocos-based App

The Crash service of AppGallery Connect provides a simple, coding-free solution for app crashes. It is found that Cocos Creator also supports the Crash service provided by AppGallery Connect. Let’s see how it works.If you want to quickly experience this service, see the demo on GitHub.
1. Creating an App and Enabling the Crash Service
1.1 Setting a Cocos App ID
Cocos app ID is the unique identifier of a game app. Before using services, you need to set a Cocos app ID for your game project.
If you do not have a Cocos-based game, click Dashboard to create one in the Cocos Account Center, as shown in the following figure.
{
"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"
}
In the Cocos Account Center, click Create a game, complete your game information, and obtain the generated app ID.
Return to Cocos Creator, click Set Cocos AppID, and choose the game to associate it.
1.2 Enabling HUAWEI Analytics and Crash in Cocos Creator
In the Service panel, enable HUAWEI Analytics and Crash.
You can also view the enabled services (highlighted) in the Cocos Account Center, as shown in the following figure.
1.3 Enabling HUAWEI Analytics and Crash in AppGallery Connect
You also need to enable the services in AppGallery Connect. The steps are as follows:
a) Sign in to AppGallery Connect, create a project, and add an app to it. For details about how to create an app in AppGallery Connect, check the official documentation.
b) In AppGallery Connect, click My projects, select a project, go to Quality > Crash, and click Enable now to enable both HUAWEI Analytics and Crash.
c) Go to Project settings and download the latest agconnect-services.json file.
d) Save the downloaded agconnect-services.json file to the settings directory in your Cocos project.
The file is also displayed in Cocos Creator, as shown in the following figure.
2. Building and Installing an App
2.1 Releasing your app in AppGallery Connect
a) In Cocos Creator, go to Project > Build…, choose HUAWEI AppGallery Connect, and set a package name. The package name must be the same as that configured in AppGallery Connect. Otherwise, a compilation error will be reported.
b) Click Build, and then Compile. You can find the corresponding APK file in the \build\jsb-link\publish\android directory of the project. You can run the adb command after a USB cable has been connected to install the package on your phone for testing.
c) You can also upload the APK file to AppGallery Connect by clicking Upload next to Compile. Select a sign-in type, fill in the relevant information, and click Confirm.
2.2 Releasing your app to an Android platform
a) In the Build… panel, choose Android for Platform, connect a phone to your computer, and click Play to install the APK file to your phone.
b) You can also open the project in the \build\jsb-link\frameworks\runtime-src\proj.android-studio directory in Android Studio.
3. Testing the Crash Service
Usually, app crashes are not common. You can manually trigger a crash and test the Crash service by calling the AGConnectCrash.testIt method of the Crash SDK and then checking whether the crash data is reported in AppGallery Connect.
In this example, a test button CrashTest is created. You can click the button to trigger a crash. The API is defined as follows:
testIt(): void
Sample code:
huawei.agc.crash.CrashService.testIt();
4. Viewing a Crash Report
4.1 Viewing crash statistics
a) Package and run your app. Tap CrashTest to trigger a crash. Exit the app and launch it again.
b) In AppGallery Connect, click My projects.
c) Find your project from the project list and click your app on the project card.
d) Go to Quality > Crash. On the Crash page, click the Statistics tab and select Last hour to view crash statistics of your app.
4.2 Viewing crash stack details
Click the crash name to go to the crash details page. Click the Stack tab. The possible causes of the crash are displayed, helping you analyze the crash.
4.3 Obtaining a readable crash report
a) When ProGuard or DexGuard overrides class names, fields, and methods in code with unreadable code during building, you can obtain a de-obfuscation crash report from the obfuscation mapping file.
b) Find the obfuscation mapping file in the following directory in Android Studio and download the file.
c) On the Mapping file tab page in AppGallery Connect, click Upload.
d) It is found that the data is restored.
Summary
1. It is simple to integrate the Crash SDK into a Cocos-based app. You just need to create an app and enable HUAWEI Analytics and Crash.
2. If it is your first time integrating the SDK, you can use a demo app for testing.
3. In addition to Crash, some other Huawei services have started to support Cocos-based apps.
For more details, please check:
1. Cocos official documentation:
https://docs.cocos.com/creator/manual/en/cocos-service/agc-crash.html
2. HUAWEI AppGallery Connect Crash documentation:
https://developer.huawei.com/consum...Gallery-connect-Guides/agc-crash-introduction
3. HUAWEI AppGallery Connect Crash codelab:
https://github.com/AppGalleryConnect/agc-crash-codelab-java
4. Cocos Creator Integrates with AppGallery Connect APM — Releasing a Cocos-based App:
https://forums.developer.huawei.com/forumPortal/en/topic/0202382127496450426?fid=0101187876626530001
if you have any question, please refer to stackoverflow.

Intermediate: How to integrate Huawei Auth Service in Unity

Introduction
In this article, we will cover how to verify Phone Number and Anonymous Account Login using Huawei Auth Service in Unity Project using Official Plugin (Huawei HMS Core App Services). AppGallery Connect provides a cloud-based Auth Service and SDKs to help you quickly build a secure and reliable user authentication system for your apps to verify user identity.
The AppGallery Connect Auth service supports multiple authentication methods and is seamlessly integrated with other server less services to secure user data based on simple rules that you have defined.
Key Functions​Using the AppGallery Auth Service SDK, you can integrate one or more of the following authentication methods into your app for achieving easy and efficient user registration and sign-in.
Self-owned account: Your self-owned account is used to support the access of your existing authentication system, so that your existing users can access other server less services in a secure manner.
Anonymous account: Anonymous accounts can be used to access your apps as visitors. The Auth service can assign user IDs to your app visitors, so that they can access other server less services in a secure manner. A visitor can be registered as a formal user and retain the original user ID to ensure service continuity.
Third-party accounts: AppGallery Connect allows user identity to be verified by third-party authentication services. The AppGallery Auth Service SDK supports the following accounts for user identity verification:
1. HUAWEI account
2. HUAWEI Game Service account
3. Phone number
4. Email account
5. WeChat account
6. Weibo account
Development Overview
You need to install Unity software and I assume that you have prior knowledge about the unity and C#.
Hardware Requirements
A computer (desktop or laptop) running Windows 10.
A Huawei phone (with the USB cable), which is used for debugging.
Software Requirements
Java JDK installation package.
Unity software installed.
Visual Studio/Code installed.
HMS Core (APK) 4.X or later.
Follows the steps.
1. Create Unity Project.
Open Unity Hub.
Click NEW, select 3D, Project Name and Location.
Click CREATE, as follows
{
"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. Click Asset Store, search Huawei HMS Core App Services and click Import, as follows.
3. Once import is successful, verify directory in Assets > Huawei HMS Core App Services path, as follows.
4. Choose Edit > Project Settings > Player and edit the required options in Publishing Settings, as follows.
5. Generate a SHA-256 certificate fingerprint.
To generating SHA-256 certificate fingerprint use below command
keytool -list -v -keystore D:\Unity\projects_unity\file_name.keystore -alias alias_name
6. Download agconnect-services.json and copy and paste to Assets > Plugins > Android, as follows.
7. Choose Project Settings > Player and update package name.
8. Open LauncherTemplate.gradle and add below line.
apply plugin: 'com.huawei.agconnect'
implementation 'com.huawei.agconnect:agconnect-auth:1.4.2.301'
implementation 'com.huawei.hms:base:5.2.0.300'
implementation 'com.huawei.hms:hwid:5.2.0.300'
9. Open AndroidManifest file and add below permissions.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
10. Open "baseProjectTemplate.gradle" and add lines, as follows.
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
maven {url 'https://developer.huawei.com/repo/'}
11. Open "mainTemplate.gradle" and add lines like shown below.
implementation 'com.huawei.agconnect:agconnect-auth:1.4.2.301'
implementation 'com.huawei.hms:base:5.2.0.300'
implementation 'com.huawei.hms:hwid:5.2.0.300'
12. Create MainActivity.java class inside Plugin > Android folder.
13. Follow the steps, as shown in image:
a. Assign Ads script to Canvas.
b. Select Button and add onclick event
c. Assign all button to button handler as per your requirements.
14. Onclick Button Handler you find your script HMSAuthService (As per your script name) and attach method as per below screen shot.
15. To build apk and run in device, choose File > Build Settings > Build for apk or Build and Run for run on connected device.
Result
1. Click on Anonymous Login, send OTP and Verify button you can see below results.
2. Find the details in AppGallery Connect, as follows.
Tips and Tricks
Always use the latest version of the library.
Add agconnect-services.json file without fail.
Add SHA-256 fingerprint without fail.
Make sure dependencies added in build files.
Make sure that you enabled the auth service in AG-Console.
Make sure that you enabled the Authentication mode in Auth Service.
Conclusion
In this article, we have learnt integration of Huawei Auth Service-AGC anonymous account login and mobile number verification through OTP in Unity Game development. Auth Service provides secure and reliable user authentication system to your application.
Thanks for reading the article, please do like and comment your queries or suggestions.
References
Unity Auth Service Manual
Auth Service
Checkout in forum

Categories

Resources