目录

HmsMessaging

Public Method Summary

Qualifier and Type

Method Name and Description

Promise<string | null>

getToken()

Obtains a push token.

Promise<boolean>

deleteToken(token: string)

Deletes a push token.

() =>void

onMessage(callback: AsyncCallback<payload>)

Obtains the push message content.

void

usePublicVapidKey(b64PublicKey: string)

Initializes the Voluntary Application Server Identity. The key is used to send and receive notification messages of the web app.

Public Methods

[h2]getToken()

Method

getToken(): Promise<string | null>

Obtains a token.

Returns

Type

Description

Promise<string | null>

Push token. If an empty string is returned, the push token fails to be obtained.

[h2]deleteToken(token: string)

Method

deleteToken(token: string): Promise<boolean>

Deletes a push token.

Parameters

Name

Description

token

Push token to be deleted.

Returns

Type

Description

Promise<boolean>

Whether the push token is deleted successfully.

  • true: yes
  • false: no

[h2]onMessage()

Method

onMessage(callback: AsyncCallback<payload>): ()=> void

Obtains the push message content.

Example

// Obtain an HmsMessaging object.
messaging = hms.messaging();
// Call the onMessage method to obtain the message content.
messaging.onMessage((payload) => {
    console.log('Message received. ', payload);
});

[h2]usePublicVapidKey(b64PublicKey: string)

Method

usePublicVapidKey(b64PublicKey: string): void

Initializes the Voluntary Application Server Identity. The key is used to send and receive notification messages of the web app.

Parameters

Name

Description

b64PublicKey

Key string encrypted using Base64.