5.2.0-300 ā€¢ Published 4 years ago

@hmscore/hms-js-gameservice v5.2.0-300

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
4 years ago

JSB GameService

Contents

1. Introduction

2. Installation Guide

Creating a Project in AppGallery Connect

Creating an app in AppGallery Connect is required in order to communicate with the Huawei services. To create an app, perform the following steps:

Step 1. Sign in to AppGallery Connect and select My projects.

Step 2. Select your project from the project list or create a new one by clicking the Add Project button.

Step 3. Go to Project Setting > General information, and click Add app. If an app exists in the project and you need to add a new one, expand the app selection area on the top of the page and click Add app.

Step 4. On the Add app page, enter the app information, and click OK.

  • A signing certificate fingerprint is used to verify the authenticity of an app when it attempts to access an HMS Core service through the HMS Core SDK. Before using HMS Core (APK), you must locally generate a signing certificate fingerprint and configure it in AppGallery Connect. Ensure that the JDK has been installed on your computer.

Configuring the Signing Certificate Fingerprint

Step 1. Go to Project Setting > General information. In the App information field, click the icon next to SHA-256 certificate fingerprint, and enter the obtained SHA256 certificate fingerprint.

Step 2. After completing the configuration, click check mark.

React-Native Integration

Step 1: Sign in to AppGallery Connect and select My projects.

Step 2: Find your app project, and click the desired app name.

Step 3: Go to Project Setting > General information. In the App information section, click agconnect-service.json to download the configuration file.

Step 4: Create a React Native project if you do not have one.

Step 5: Copy the agconnect-service.json file to the android/app directory of your React Native project.

Step 6: Copy the signature file that generated in Generating a Signing Certificate section, to the android/app directory of your React Native project.

Step 7: Check whether the agconnect-services.json file and signature file are successfully added to the android/app directory of the React Native project.

Step 8: Open the AndroidManifest.xml file, add the following lines, and replace the value <app_id> with the value you found in the agconnect-services.json file.

<application>
...
  <meta-data
    android:name="com.huawei.hms.client.appid"
    android:value="appid=<app_id>" />
</application>

Step 9: Open the build.gradle file in the android directory of your React Native project.

  • Go to buildscript then configure the Maven repository address and agconnect plugin for the HMS SDK.
buildscript {
  repositories {
    google()
    jcenter()
    maven { url 'https://developer.huawei.com/repo/' }
  }

  dependencies {
    /*
      * <Other dependencies>
      */
    classpath 'com.huawei.agconnect:agcp:1.4.2.301'
  }
}
  • Go to allprojects then configure the Maven repository address for the HMS SDK.
allprojects {
  repositories {
    /*
      * <Other repositories>
      */
    maven { url 'https://developer.huawei.com/repo/' }
  }
}

Step 10: Open the build.gradle file in the android/app directory of your React Native project.

  • Package name must match with the package_name entry in agconnect-services.json file.
defaultConfig {
  applicationId "<package_name>"
  minSdkVersion 19
  /*
   * <Other configurations>
   */
}
android {
  /*
   * <Other configurations>
   */

  signingConfigs {
    config {
      storeFile file('<keystore_file>.jks')
      storePassword '<keystore_password>'
      keyAlias '<key_alias>'
      keyPassword '<key_password>'
    }
  }

  buildTypes {
    debug {
      signingConfig signingConfigs.config
    }
    release {
      signingConfig signingConfigs.config
      minifyEnabled enableProguardInReleaseBuilds
      ...
    }
  }
}

Step 11: Open the build.gradle file in the android/app directory of your React Native project.

  • Configure build dependencies.
buildscript {
  ...
  dependencies {
    /*
    * <Other dependencies>
    */
    implementation ('com.huawei.hms:rn-adapter:5.2.0.300'){
        exclude group: 'com.facebook.react'
    }
    ...
  }
}

Step 12: Import the following class to the MainApplication.java file of your project.

import com.huawei.hms.jsb.adapter.rn.RnJSBReactPackage;

Then, add the RnJSBReactPackage() to your getPackages method. In the end, your file will be similar to the following:

@Override
protected List<ReactPackage> getPackages() {
    List<ReactPackage> packages = new PackageList(this).getPackages();
    packages.add(new RnJSBReactPackage()); // <-- Add this line
    return packages;
}
...

Step 13: Download js-sdk using command below.

npm i @hmscore/hms-js-gameservice

Step 14: Import HMSGameService in App.js as following line.

import HMSGameService from "@hmscore/hms-js-gameservice";

Step 15: First you have to call the init function.

import {NativeModules, DeviceEventEmitter} from "react-native";
...
HMSGameService.init(NativeModules, DeviceEventEmitter);

Step 16: Run your project.

  • Run the following command to the project directory.
react-native run-android

Cordova Integration

Step 1: Install Cordova CLI if haven't done before.

npm install -g cordova

Step 2: Create a new Cordova project or use the existing one.

  • To create new Cordova project, you can use cordova create path [id [name [config]]] [options] command. For more details please follow CLI Reference - Apache Cordova.

Step 3: Update the widget id property which is specified in the config.xml file. It must be same with package_name value of the agconnect-services.json file.

Step 4: Add the Android platform to the project if haven't done before.

cordova platform add android

Step 5: Download plugin using command below.

cordova plugin add @hmscore/hms-js-gameservice

Step 6: Copy agconnect-services.json file to <project_root>/platforms/android/app directory.

Step 7: Add keystore(.jks) and build.json files to your project's root directory.

  • You can refer to 3rd and 4th steps of Generating a Signing Certificate Codelab tutorial page for generating keystore file.

  • Fill build.json file according to your keystore information. For example:

    {
      "android": {
        "debug": {
          "keystore": "<keystore_file>.jks",
          "storePassword": "<keystore_password>",
          "alias": "<key_alias>",
          "password": "<key_password>"
        },
        "release": {
          "keystore": "<keystore_file>.jks",
          "storePassword": "<keystore_password>",
          "alias": "<key_alias>",
          "password": "<key_password>"
        }
      }
    }
**Step 8:** Import the following class to the **MainActivity.java** file of your project. You can find this file in **`platforms/android/app/src/main/java/<your_package_name>`** directory.

ā€‹```java
import com.huawei.hms.jsb.adapter.cordova.CordovaJSBInit;

Step 9: In the same file, add CordovaJSBInit.initJSBFramework(this) line after the super.onCreate(savedInstanceState) method call.

  • In the end, your file will be similar to the following:
  ...

  import com.huawei.hms.jsb.adapter.cordova.CordovaJSBInit;

  public class MainActivity extends CordovaActivity
  {
      @Override
      public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          CordovaJSBInit.initJSBFramework(this);

          ...
      }
      ...
  }
**Step 10:** Open the **AndroidManifest.xml** file, add the following lines, and replace the value **<app_id>** with the **app_id** value that can be found in the **agconnect-services.json** file.

ā€‹```xml
<application>
...
     <meta-data
            android:name="com.huawei.hms.client.appid"
            android:value="appid=<app_id>" />
</application>

Step 11: Run the app

cordova run android

Ionic Integration

Install Ionic CLI and other required tools if haven't done before.

npm install -g @ionic/cli cordova-res native-run

Ionic with Cordova Runtime

Step 1: Enable the Cordova integration if haven't done before.

ionic integrations enable cordova

Step 2: Update the widget id property which is specified in the config.xml file. It must be same with package_name value of the agconnect-services.json file.

Step 3: Add the Android platform to the project if haven't done before.

ionic cordova platform add android

Step 4: Install HMS Game Service Plugin to the project.

ionic cordova plugin add @hmscore/hms-js-gameservice

Step 5: Copy agconnect-services.json file to <project_root>/platforms/android/app directory.

Step 6: Add keystore(.jks) and build.json files to your project's root directory.

  • You can refer to 3rd and 4th steps of Generating a Signing Certificate Codelab tutorial page for generating keystore file.

  • Fill build.json file according to your keystore information. For example:

{
  "android": {
    "debug": {
      "keystore": "<keystore_file>.jks",
      "storePassword": "<keystore_password>",
      "alias": "<key_alias>",
      "password": "<key_password>"
    },
    "release": {
      "keystore": "<keystore_file>.jks",
      "storePassword": "<keystore_password>",
      "alias": "<key_alias>",
      "password": "<key_password>"
    }
  }
}

Step 7: Import the following class to the MainActivity.java file of your project. You can find this file in platforms/android/app/src/main/java/<your_package_name> directory.

import com.huawei.hms.jsb.adapter.cordova.CordovaJSBInit;

Step 8: In the same file, add CordovaJSBInit.initJSBFramework(this) line after the super.onCreate(savedInstanceState) method call.

  • In the end, your file will be similar to the following:
...

import com.huawei.hms.jsb.adapter.cordova.CordovaJSBInit;

public class MainActivity extends CordovaActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        CordovaJSBInit.initJSBFramework(this);

        ...
    }
    ...
}

Step 9: Open the AndroidManifest.xml file, add the following lines, and replace the value <app_id> with the app_id value that can be found in the agconnect-services.json file.

<application>
...
  <meta-data
    android:name="com.huawei.hms.client.appid"
    android:value="appid=<app_id>" />
</application>

Step 10: Run the application.

ionic cordova run android --device

Ionic with Capacitor Runtime

Step 1: Enable the Capacitor integration if haven't done before.

ionic integrations enable capacitor

Step 2: Initialize Capacitor if haven't done before.

npx cap init [appName] [appId]

Step 3: Update the appId property which is specified in the capacitor.config.json file according to your project. It must be same with package_name value of the agconnect-services.json file.

Step 4: Install HMS Game Service plugin to the project.

npm install @hmscore/hms-js-gameservice

Step 5: Build Ionic app to generate resource files.

ionic build

Step 6: Add the Android platform to the project.

npx cap add android

Step 7: Copy keystore(.jks) and agconnect-services.json files to <project_root>/android/app directory.

Step 8: Open the build.gradle file in the <project_root>/android/app directory.

  • Add signingConfigs entry to the android section and modify it according to your keystore.

  • Enable signingConfig configuration for debug and release flavors.

...

android {

    ...

    // Modify signingConfigs according to your keystore
    signingConfigs {
        config {
            storeFile file('<keystore_file>.jks')
            storePassword '<keystore_password>'
            keyAlias '<key_alias>'
            keyPassword '<key_password>'
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.config // Enable signingConfig for debug flavor
        }
        release {
            signingConfig signingConfigs.config // Enable signingConfig for release flavor
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

...
  • Add apply plugin:'com.huawei.agconnect to top of your build gradle file in the <project_root>/android/app directory.

Step 9: Open the build.gradle file in the <project_root>/android directory. Add Huawei's maven repositories and agconnect classpath to the file.

buildscript {
    repositories {
        /*
            <Other repositories>
        */
        maven { url 'https://developer.huawei.com/repo/' }
    }
    dependencies {
        /*
            <Other dependencies>
        */
        classpath 'com.huawei.agconnect:agcp:1.4.2.301'
    }
}

/*
    <Other build.gradle entries>
*/

allprojects {
    repositories {
        /*
            <Other repositories>
        */
        maven { url 'https://developer.huawei.com/repo/' }
    }
}

Step 10: Import the following class to the MainActivity.java file of your project. You can find this file in android/app/src/main/java/<your_package_name> directory.

import com.huawei.hms.js.gameservice.HMSGameService;

Step 11: In the same file, add add(HMSGameService.class); line to the ArrayList.

  • In the end, your file will be similar to the following:

    ...
    import com.huawei.hms.js.gameservice.HMSGameService;
    public class MainActivity extends BridgeActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
    
      // Initializes the Bridge
      this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
          add(HMSGameService.class);
      }});
    }
    ...

Step 12: Open the AndroidManifest.xml file, add the following lines, and replace the value <app_id> with the app_id value that can be found in the agconnect-services.json file.

<application>
...
     <meta-data
            android:name="com.huawei.hms.client.appid"
            android:value="appid=<app_id>" />
</application>

Step 13: Updates dependencies, and copy any web assets to your project.

npx cap sync

Step 14: Open the project in Android Studio and run it.

npx cap open android

3. API Reference

HMSGameService

Public Method Summary

MethodReturn TypeDescription
signInPromise<Result\>This API allows you to log in for the huawei game service.
silenSignInPromise<Result\>The silentSignIn method allows users to use the same HUAWEI ID without authorization for subsequent sign-ins.
signOutPromise<Result\>This API allows you to log out for the huawei game service.
isShowBuoyPromise<Result\>Displays the floating window.
getCurrentPlayerPromise<Result\>Obtains the object of the current player.
getCachePlayerId()Promise<Result\>Obtains the locally cached player ID of the current player.
getCachePlayer()Promise<Result\>Obtains the locally cached player information of the current player.
getAchievementsIntent()Promise<Result\>Obtains the list of all game achievements of the current player.
incrementAchievement(achievementId,numSteps)Promise<Result\>Asynchronously increases an achievement by the given number of steps.
incrementAchievementImmediate(achievementId,numSteps)Promise<Result\>Synchronously increases an achievement by the given number of steps.
loadAchievementList(forceLoad)Promise<Result\<List\>>Obtains the list of achievements in all statuses for the current player.
eventIncrement(eventId,incrementAmount)Promise<Result\>Submits the event data of the current player.
revealAchievement(achievementId)Promise<Result\>Asynchronously reveals a hidden achievement to the current player.
revealAchievementImmediate(achievementId)Promise<Result\>Synchronously reveals a hidden achievement to the current player.
setAchievementSteps(achievementId,numSteps)Promise<Result\>Asynchronously sets an achievement to have the given number of steps completed.
setAchievementStepsImmediate(achievementId,numSteps)Promise<Result\>Synchronously sets an achievement to have the given number of steps completed.
unlockAchievement(achievementId)Promise<Result\>Asynchronously unlocks an achievement for the current player.
unlockAchievementImmediate(achievementId)Promise<Result\>Synchronously unlocks an achievement for the current player.
loadEventList(forceReload, eventIds)Promise<Result\<List\>>Obtains all event data of the current player with ID or without ID.
getAllRankingsIntent()Promise<Result\>Obtains the Intent object of the leaderboard list page.
getRankingByTimeIntent(rankingId,timeDimension)Promise<Result\>Obtains the Intent object of the page for a specified leaderboard in a specified time frame.
getRankingIntent(rankingId)Promise<Result\>Obtains the Intent object of the page for a specified leaderboard in all time frames.
loadTopScorePage(rankingId,timeDimension, maxResults,offsetPlayerRank,pageDirection)Promise<Result\>Obtains the scores on the first page of a leaderboard from Huawei game server.
loadTopScore(rankingId,timeDimension, maxResults,isRealTime)Promise<Result\>Obtains scores on the first page of a leaderboard. The data can be obtained from the local cache.
submitScore(rankingId,score)Promise<Result\>Asynchronously submits the score of the current player without a custom unit.
submitScoreTag(rankingId,score,scoreTips)Promise<Result\>Asynchronously submits the score of the current player with a custom unit.
submitScoreImmediate(rankingId,score)Promise<Result\>Synchronously submits the score of the current player without a custom unit.
submitScoreImmediateTag(rankingId,score,scoreTips)Promise<Result\>Synchronously submits the score of the current player with a custom unit.
getRankingsSwitchStatus()Promise<Result\>Obtains the current player's leaderboard switch setting.
setRankingsSwitchStatus(status)Promise<Result\>Sets the leaderboard switch for the current player.
getCurrentGameMetadata()Promise<Result\>Obtains the information about the current game from the local cache.
loadGameMetadata()Promise<Result\>Obtains the information about the current game from Huawei game server. If the obtaining fails, the information will then be obtained from the local cache.
loadGamePlayerStats(isRealTime)Promise<Result\>Obtains the statistics of the current player, such as the session duration and rank.
loadCurrentPlayerRankingScore(rankingId,timeDimension)Promise<Result\>Obtains the score of a player on a specified leaderboard in a specified time frame.
loadRankingMetadata(rankingId,isRealTime)Promise<Result\>Obtains the data of a leaderboard. The data can be obtained from the local cache.
loadRankingsMetadata(isRealTime)Promise<Result\>Obtains all leaderboard data. The data can be obtained from the local cache.
loadMoreScores(rankingId,offsetPlayerRank,maxResults, pageDirection,timeDimension)Promise<Result\>Obtains scores on a leaderboard in a specified time frame in pagination mode.
loadPlayerCenteredPageScores(rankingId,timeDimension,maxResults,offsetPlayerRank, pageDirection)Promise<Result\>Obtains scores of a leaderboard with the current player's score displayed in the page center from Huawei game server.
loadPlayerCenteredScores(rankingId,timeDimension,maxResults, isRealTime)Promise<Result\>Obtains scores of a leaderboard with the current player's score displayed in the page center. The data can be obtained from the local cache.
getPlayerExtraInfo(transactionId)Promise<Result\>Obtains the additional information about a player.
submitPlayerEvent(playerId,eventId,eventType)Promise<Result\>Reports player behavior events.
savePlayerInfo(rank, role, area, sociaty, playerId, openId)Promise<Result\>Saves the information about the player in the current game.
checkGameServiceLite()Promise<Result\>Checks game service.
checkMobile(checkWithOpenId, mobile, gameAppId, playerId, ts, transactionId, inputSign)Promise<Result\>
cancelGameService()Promise<Result\>Revokes the authorization to HUAWEI Game Service.
getPlayerRestTime(transactionId)Promise<Result\>Returns player real name

3.1.2 Public Methods

signIn()

Return TypeDescription
Promise<Result\>Returns object containing login information

Call Example

HMSGameService.signIn()
    .then((res) =>{console.log(JSON.stringify(res))})    
    .catch((err) =>{console.log(JSON.stringify(err))})

signOut()

Return TypeDescription
Promise<Result\>Returns object containing logout information

Call Example

HMSGameService.signOut()
    .then((res) =>{console.log(JSON.stringify(res))})    
    .catch((err) =>{console.log(JSON.stringify(err))})

silenSignIn ()

Return TypeDescription
Promise<Result\>Returns object containing sign in information

Call Example

HMSGameService.silenSignIn()
    .then((res) =>{console.log(JSON.stringify(res))})    
    .catch((err) =>{console.log(JSON.stringify(err))})

isShowBuoy()

Return TypeDescription
Promise<Result\>Displays the floating window.

Call Example

HMSGameService.isShowBuoy()
     .then((res) =>{console.log(JSON.stringify(res))})
     .catch((err) =>{console.log(JSON.stringify(err))})

getCurrentPlayer()

Return TypeDescription
Promise<Result\>Returns the details about a player.

Call Example

HMSGameService.getCurrentPlayer()
     .then((player) => {console.log(JSON.stringify(player))})     
     .catch((err) =>{console.log(JSON.stringify(err))})

getCachePlayerId()

Return TypeDescription
Promise<Result\>ID of a player in a game.

Call Example

HMSGameService.getCachePlayerId()
     .then((player) => {console.log(JSON.stringify(player))})
     .catch((err) =>{console.log(JSON.stringify(err))})

getCachePlayer()

Return TypeDescription
Promise<Result\>ID of a player in a game.

Call Example

HMSGameService.getCachePlayer()
     .then((player) => {console.log(JSON.stringify(player))})     
     .catch((err) =>{console.log(JSON.stringify(err))})

getAchievementsIntent()

Return TypeDescription
Promise<Result\>Intent object containing the achievement list. An app can call the startActivityForResult method to access the achievement list.

Call Example

HMSGameService.getAchievementsIntent()
     .then((res) =>{console.log(JSON.stringify(res))})    
     .catch((err) =>{console.log(JSON.stringify(err))})

incrementAchievement(achievementId,numSteps)

ParameterTypeDescription
achievementIdstringID of the achievement requiring step increase.
numStepsnumberNumber of steps to be increased. The value must be greater than 0.
Return TypeDescription
Promise<Result\>Asynchronously increases an achievement by the given number of steps.

Call Example

HMSGameService.getAchievementsIntent()
     .then((res) =>{console.log(JSON.stringify(res))})
     .catch((err) =>{console.log(JSON.stringify(err))})

incrementAchievementImmediate(achievementId,numSteps)

ParameterTypeDescription
achievementIdstringID of the achievement requiring step increase.
numStepsnumberNumber of steps to be increased. The value must be greater than 0.
Return TypeDescription
Promise<Result\>true if the execution is successful; false if the API call is successful but the execution fails. If false is returned, ensure that the achievement ID and number of steps to be increased are correct.

Call Example

const achievementId = "958D2546B5663BE6D439A7A2C505422127CB661952D**********"
const numSteps = 1
HMSGameService.incrementAchievementImmediate(achievementId,numSteps)
     .then((res) =>{console.log(JSON.stringify(res))})
     .catch((err) =>{console.log(JSON.stringify(err))})

loadAchievementList(forceLoad)

ParameterTypeDescription
forceLoadbooleanIndicates whether to obtain the achievement list from the server or client. The options are as follows:true: server false: client
Return TypeDescription
Promise<Result\<Achievement[]>>Return a Achievement array.

Call Example

const forceReload = true
HMSGameService.loadAchievementList(forceReload)   
    .then((res) =>{console.log(JSON.stringify(res))})    
    .catch((err) =>{console.log(JSON.stringify(err))})

eventIncrement(eventId,incrementAmount)

ParameterTypeDescription
eventIdstringID of the event to be submitted. The value is obtained after you configure the event.
incrementAmountnumberIncrement amount of the existing event value.
Return TypeDescription
Promise<Result\>Submits event data.

Call Example

const eventId = "E5E02A4A2D6A0C36C45A77CDF11D24D785C030ABE49A*********"
const growAmount = 1
HMSGameService.eventIncrement(eventId, growAmount)
    .then((res) =>{console.log(JSON.stringify(res))})
    .catch((err) =>{console.log(JSON.stringify(err))})

revealAchievement(achievementId)

ParameterTypeDescription
achievementIdstringID of the achievement to be revealed.
Return TypeDescription
Promise<Result\>Asynchronously reveals a hidden achievement of a game.

Call Example

const achievementId ="958D2546B5663BE6D439A7A2C505422127CB661952D356**********"
HMSGameService.revealAchievement(achievementId)
    .then((res) =>{console.log(JSON.stringify(res))})
    .catch((err) =>{console.log(JSON.stringify(err))})

revealAchievementImmediate(achievementId)

ParameterTypeDescription
achievementIdstringID of the achievement to be revealed.
Return TypeDescription
Promise<Result\>Immediately reveals a hidden achievement of a game.

Call Example

const achievementId ="958D2546B5663BE6D439A7A2C505422127CB661952D356**********"
HMSGameService.revealAchievementImmediate(achievementId)
    .then((res) =>{console.log(JSON.stringify(res))})
    .catch((err) =>{console.log(JSON.stringify(err))})

setAchievementSteps(achievementId,numSteps)

ParameterTypeDescription
achievementIdstringID of the achievement requiring step setting.
numStepsnumberNumber of steps to be set. The value must be greater than 0.
Return TypeDescription
Promise<Result\>Asynchronously sets the number of completed steps of an achievement.

Call Example

const achievementId ="958D2546B5663BE6D439A7A2C505422127CB661952D356**********"
var numSteps = 3;
HMSGameService.setAchievementSteps(achievementId, numSteps)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))})

setAchievementStepsImmediate(achievementId,numSteps)

ParameterTypeDescription
achievementIdstringID of the achievement requiring step setting.
numStepsnumberNumber of steps to be set. The value must be greater than 0.
Return TypeDescription
Promise<Result\>true if the execution is successful; false if the API call is successful but the execution fails. If false is returned, ensure that the achievement ID and number of steps to be increased are correct.

Call Example

const achievementId ="958D2546B5663BE6D439A7A2C505422127CB661952D356**********"
var numSteps = 3;
HMSGameService.setAchievementSteps(achievementId, numSteps)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))})

unlockAchievement(achievementId)

ParameterTypeDescription
achievementIdstringID of the achievement to be unlocked.
Return TypeDescription
Promise<Result\>Asynchronously unlocks an achievement for the current player.

Call Example

const achievementId ="958D2546B5663BE6D439A7A2C505422127CB661952D356**********"
HMSGameService.unlockAchievement(achievementId)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))})

unlockAchievementImmediate(achievementId)

ParameterTypeDescription
achievementIdstringID of the achievement to be unlocked.
Return TypeDescription
Promise<Result\>Immediately unlocks an achievement for the current player.

Call Example

const achievementId ="958D2546B5663BE6D439A7A2C505422127CB661952D356**********"
HMSGameService.unlockAchievementImmediate(achievementId)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))})

loadEventList(forceReload, eventIds)

ParameterTypeDescription
achievementIdstringIndicates whether to load the event list stored on the server or cached locally. The options are as follows: true: server false: local cache
eventIdsstring[]IDs of the events to be obtained. The value is a string array.
Return TypeDescription
Promise<Result\<Event[]>>Return an Event array.

Call Example

const forceReload = true;
const achievementId ="958D2546B5663BE6D439A7A2C505422127CB661952D356**********"
HMSGameService.loadEventList(forceReload, eventId)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))})   

getAllRankingsIntent()

Return TypeDescription
Promise<Result\>Intent object of a leaderboard.

Call Example

HMSGameService.getAllRankingsIntent()
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

getRankingByTimeIntent()

ParameterTypeDescription
rankingIdstringID of a leaderboard for which data is to be obtained.
timeDimensionnumberTime frame. The options are as follows: 0: The daily leaderboard is obtained. 1: The weekly leaderboard is obtained. 2: The all-time leaderboard is obtained.
Return TypeDescription
Promise<Result\>Intent object of the leaderboard list page.

Call Example

const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
const timeDimension = 1;
HMSGameService.getRankingByTimeIntent(rankingId, timeDimension)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

getRankingIntent(rankingId)

ParameterTypeDescription
rankingIdstringID of a leaderboard for which data is to be obtained.
Return TypeDescription
Promise<Result\>Intent object of a leaderboard.

Call Example

const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
HMSGameService.getRankingIntent(rankingId)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

loadTopScorePage(rankingId,timeDimension, maxResults,offsetPlayerRank,pageDirection)

ParameterTypeDescription
rankingIdstringID of a leaderboard for which data is to be obtained.
timeDimensionnumberTime frame. The options are as follows: 0: daily 1: weekly 2: all-time
maxResultsnumberMaximum number of records on each page. The value is an number ranging from 1 to 21.
offsetPlayerRanknumberIRank specified by offsetPlayerRank. Then one page of scores before or after (specified by pageDirection) a rank will be loaded. The value of offsetPlayerRank must be 0 or a positive number.
pageDirectionnumberData obtaining direction. Currently, only the value 0 is supported, indicating that data of the next page is obtained.
Return TypeDescription
Promise<Result\>Scores on the first page of a leaderboard.

Call Example

const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
const timeDimension = 2;
const maxResults = 20;
const offsetPlayerRank = 0;
const pageDirection = 0;
HMSGameService.loadTopScorePage(
rankingId,
    timeDimension,
    maxResults,
    offsetPlayerRank,
    pageDirection
)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

loadTopScore(rankingId,timeDimension, maxResults,isRealTime)

ParameterTypeDescription
rankingIdstringID of a leaderboard for which data is to be obtained.
timeDimensionnumberTime frame. The options are as follows: 0: daily1: weekly2: all-time
maxResultsnumberMaximum number of records on each page. The value is an number ranging from 1 to 21.
isRealTimebooleanIndicates whether to obtain leaderboard data from Huawei game server. The options are as follows:true: Obtain data from Huawei game server. false: Obtain data from the local cache.
Return TypeDescription
Promise<Result\>Scores on the first page of a leaderboard.

Call Example

const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
const timeDimension = 2;
const maxResults = 20;
const isRealTime = true;
HMSGameService.loadTopScore(
    rankingId,
    timeDimension,
    maxResults,
    isRealTime
)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

submitScore(rankingId,score)

ParameterTypeDescription
rankingIdstringID of a leaderboard for which data is to be obtained.
scorenumberScore of the current player.
Return TypeDescription
Promise<Result\>Asynchronously submits the score of the current player without a custom unit.

Call Example

const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
const score = 20
HMSGameService.submitScore(rankingId, score)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

submitScoreTag(rankingId,score,scoreTips)

ParameterTypeDescription
rankingIdstringID of a leaderboard for which data is to be obtained.
scorenumberScore of the current player.
scoreTipsnumberScore custom unit. Only letters, digits, underscores (_), and hyphens (-) are supported.
Return TypeDescription
Promise<Result\>Asynchronously submits the score of the current player with a custom unit.

Call Example

const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
const score = 10;
const scoreTips = "scoreTips";
HMSGameService.submitScoreTag(rankingId, score, scoreTips)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

submitScoreImmediate(rankingId,score)

ParameterTypeDescription
rankingIdstringID of a leaderboard for which data is to be obtained.
scorenumberScore of the current player.
Return TypeDescription
Promise<Result\>Score submission result.

Call Example

const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
const score = 10;
HMSGameService.submitScoreImmediate(rankingId, score)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

submitScoreImmediateTag(rankingId,score,scoreTips)

ParameterTypeDescription
rankingIdstringID of a leaderboard for which data is to be obtained.
scorenumberScore of the current player.
scoreTipsnumberScore custom unit. Only letters, digits, underscores (_), and hyphens (-) are supported.
Return TypeDescription
Promise<Result\>Score submission result.

Call Example

const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
const score = 100;
const scoreTips = "scoreTips";
HMSGameService.submitScoreImmediateTag(
  rankingId,
  score,
  scoreTips
)
    .then((res) => {console.log(JSON.stringify(res))})
    .catch((err) => {console.log(JSON.stringify(err))})

getRankingsSwitchStatus()

Return TypeDescription
[Promise<Result\>Leaderboard switch setting. The setting is returned asynchronously and has the following options: 0: off 1: no

Call Example

 HMSGameService.getRankingsSwitchStatus()
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

setRankingsSwitchStatus(status)

ParameterTypeDescription
statusnumberStatus of the leaderboard switch to be set. 0: off 1: no
Return TypeDescription
[Promise<Result\>Leaderboard switch setting. The setting is returned asynchronously and has the following options: 0: off 1: no

Call Example

const status = 0 
HMSGameService.setRankingsSwitchStatus(status)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

getCurrentGameMetadata()

Return TypeDescription
Promise<Result\>A GameSummary object that contains the information about the current game.

Call Example

HMSGameService.getCurrentGameMetadata()
    .then((res) => {console.log(JSON.stringify(res))})
    .catch((err) => {console.log(JSON.stringify(err))})

loadGameMetadata()

Return TypeDescription
Promise<Result\>Information about the current game.

Call Example

HMSGameService.loadGameMetadata()
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

loadGamePlayerStats(isRealTime)

ParameterTypeDescription
isRealTimenumberIndicates whether to obtain data from Huawei game server. The options are as follows: true: Obtain data from Huawei game server false: Obtain data from the local cache. Data is kept in the local cache for 5 minutes. If there is no local cache or the cache times out, data will be obtained from the game server.
Return TypeDescription
Promise<Result\>Statistics of the current player.

Call Example

const isRealTime = true
HMSGameService.loadGamePlayerStats(isRealTime)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

loadCurrentPlayerRankingScore(rankingId,timeDimension)

ParameterTypeDescription
rankingIdstringID of a leaderboard for which data is to be obtained.
timeDimensionnumberTime frame. The options are as follows: 0: The daily leaderboard is obtained. 1: The weekly leaderboard is obtained. 2: The all-time leaderboard is obtained.
Return TypeDescription
Promise<Result\>Score of a player on a leaderboard, which is obtained from the RankingScores object that is returned.

Call Example

const timeDimension = 2;
const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
HMSGameService.loadCurrentPlayerRankingScore(
    rankingId,
    timeDimension
)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

loadRankingMetadata(rankingId,isRealTime)

ParameterTypeDescription
rankingIdstringID of a leaderboard for which data is to be obtained.
isRealTimenumberIndicates whether to obtain leaderboard data from Huawei game server. The options are as follows: true: Obtain data from Huawei game server. false: Obtain data from the local cache.
Return TypeDescription
Promise<Result\>Data of the current leaderboard.

Call Example

const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
const isRealTime = "true";
HMSGameService.loadRankingMetadata(
    rankingId,
    isRealTime
)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

loadRankingsMetadata(isRealTime)

ParameterTypeDescription
isRealTimenumberIndicates whether to obtain leaderboard data from Huawei game server. The options are as follows: true: Obtain data from Huawei game server. false: Obtain data from the local cache.
Return TypeDescription
Promise<Result\>Data of the current leaderboard.

Call Example

const isRealTime = "true";
HMSGameService.loadRankingsMetadata(isRealTime)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

loadMoreScores(rankingId,offsetPlayerRank,maxResults,pageDirection,timeDimension)

ParameterTypeDescription
rankingIdstringID of a leaderboard for which data is to be obtained.
offsetPlayerRanknumberRank specified by offsetPlayerRank. Then one page of scores before or after (specified by pageDirection) a rank will be loaded.
maxResultsnumberMaximum number of records on each page. The value is an number ranging from 1 to 21.
pageDirectionnumberData obtaining direction. The options are as follows: 0: next page 1: previous page
timeDimensionnumberTime frame in which a leaderboard is to be obtained. The options are as follows: 0: The daily leaderboard is obtained. 1: The weekly leaderboard is obtained. 2: The all-time leaderboard is obtained.
Return TypeDescription
Promise<Result\>Data of the current leaderboard.

Call Example

const offsetPlayerRank = 5;
const maxResults = 15;
const pageDirection = 0;
const timeDimension = 2;
const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
HMSGameService.loadMoreScores(
  rankingId,
  offsetPlayerRank,
  maxResults,
  pageDirection,
  timeDimension
)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

loadPlayerCenteredPageScores(rankingId,timeDimension,maxResults,offsetPlayerRank,pageDirection)

ParameterTypeDescription
rankingIdstringID of a leaderboard for which data is to be obtained.
offsetPlayerRanknumberRank specified by offsetPlayerRank. Then one page of scores before or after (specified by pageDirection) a rank will be loaded.
maxResultsnumberMaximum number of records on each page. The value is an number ranging from 1 to 21.
pageDirectionnumberData obtaining direction. The options are as follows: 0: next page 1: previous page
timeDimensionnumberTime frame in which a leaderboard is to be obtained. The options are as follows: 0: The daily leaderboard is obtained. 1: The weekly leaderboard is obtained. 2: The all-time leaderboard is obtained.
Return TypeDescription
Promise<Result\>Data of the current leaderboard.

Call Example

const timeDimension = 2;
const maxResults = 15;
const offsetPlayerRank = 0;
const pageDirection = 1;
const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
HMSGameService.loadPlayerCenteredPageScores(
    rankingId,
    timeDimension,
    maxResults,
    offsetPlayerRank,
    pageDirection
)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

loadPlayerCenteredScores(rankingId,timeDimension,maxResults,isRealTime)

ParameterTypeDescription
rankingIdstringID of a leaderboard for which data is to be obtained.
timeDimensionnumberTime frame in which a leaderboard is to be obtained. The options are as follows: 0: The daily leaderboard is obtained.1: The weekly leaderboard is obtained.2: The all-time leaderboard is obtained.
maxResultsnumberMaximum number of records on each page. The value is an number ranging from 1 to 21.
isRealTimenumberIndicates whether to obtain leaderboard data from Huawei game server. The options are as follows:true: Obtain data from Huawei game server.false: Obtain data from the local cache.
Return TypeDescription
Promise<Result\>Data of the current leaderboard.

Call Example

const timeDimension = 2;
const maxResults = 15;
const isRealTime = true;
const rankingId = "29B6B039B259E8E90F379785B868C5F23E81A02D640E7*******"
HMSGameService.loadPlayerCenteredScores(
  rankingId,
  timeDimension,
  maxResults,
  isRealTime
)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

getPlayerExtraInfo(transactionId)

ParameterTypeDescription
transactionIdstringTransaction ID returned by Huawei game server after an app calls the submitPlayerEvent method to report a player event of entering a game. If a transaction ID exists, the ID is passed. If a transaction ID does not exist, null is passed.
Return TypeDescription
Promise<Result\>Return a PlayerExtraInfo object.

Call Example

const transactionId = "A1:736563***************"
HMSGameService.getPlayerExtraInfo(transactionId)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

submitPlayerEvent(playerId,eventId,eventType)

ParameterTypeDescription
playerIdstringID of the current player.
eventIdstringPlayer event ID.
eventTypestringEvent type. The options are as follows:GAMEBEGIN: A player enters your game. GAMEEND: A player exits your game.
Return TypeDescription
Promise<Result\>Transaction ID allocated by Huawei game server to a player in the scenario where eventType is set to GAMEBEGIN. In other scenarios, null is returned

Call Example

const playerId = "718*******"
const eventType = "GAMEBEGIN"
const eventId = "F3845094040940********"
HMSGameService.submitPlayerEvent(playerId, eventId, eventType)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

savePlayerInfo(rank,role,area,sociaty,playerId,openId)

ParameterTypeDescription
rankstringObtains the level of a player in a game.
rolestringObtains the role of a player in a game.
areastringObtains the server region of a player in a game.
sociatystringObtains the guild information of a player in a game.
playerIdstringObtains the ID of a player in a game.
openIdstringObtains the OpenId of a player in a game. The OpenId uniquely identifies a HUAWEI ID in an app.
Return TypeDescription
Promise<Result\>Return a Result object.

Call Example

const rank = 1
const role = 0
const area = 1
const sociaty = 1
const playerId = "718*******"
const openId = "718*******"
HMSGameService.savePlayerInfo(rank, role, area, sociaty, playerId, openId)
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

checkGameServiceLite()

Return TypeDescription
Promise<Result\>Return a Result object.

Call Example

HMSGameService.checkGameServiceLite()
    .then((res) =>{console.log(JSON.stringify(res))})   
    .catch((err) =>{console.log(JSON.stringify(err))}) 

checkMobile(checkWithOpenId, m