To standardize notification messages for a better experience, Push Kit will be fully updated from May 19, 2023 for quick apps.
During the update, the push capability will be unavailable. That is, push messages and notification messages cannot reach users in quick apps. We apologize for any inconvenience caused to you.
The service update is expected to be completed in the fourth quarter of 2023. We will notify you by email after that. If you have any questions, please send an email to developer@huawei.com. Thank you for your support.
This function depends on the services provided by the Push SDK. The SDK may collect personal data of users. Before using this function in a quick app, inform the users that personal data will be collected and guide them to read the privacy statement.
This document describes only the definition of APIs. For details about how and when to call these APIs, please refer to Integrating Push Kit.
Add the following configuration to the features attribute in the manifest.json file:
{"name": "service.push"} Add the following configuration to the script element on the page where the API will be called:
import push from '@service.push'
Or
var push = require("@service.push") Item | Description |
|---|---|
Applicable devices | Mobile phones, tablets, and telematics devices |
Applicable regions | Global |
API | Description |
|---|---|
Obtains the service provider. | |
Subscribes to Push Kit to receive push messages. | |
Unsubscribes from Push Kit. | |
Adds a push event callback. | |
Removes the push event callback. The callback of the push.on API will not receive the content of a transparent push message any longer. |
Description
Obtains the service provider.
Returns
Character string, which is the code of the service provider (for example, the English brand name of the vendor), is returned. If the service does not exist, an empty string is returned. If so, do not call other APIs of the service. Otherwise, an exception will occur.
Use Huawei Quick App Loader for debugging.
Sample code
push.getProvider();
Description
Subscribes to Push Kit during app initialization to receive push messages. For example, call this method in the onCreate method.
OBJECT parameters
Parameter | Type | Mandatory/Optional | Description |
|---|---|---|---|
success | function | Optional | Success callback. regId is returned for sending push messages. |
fail | function | Optional | Failure callback. The cause of the failure is returned. |
complete | function | Optional | Callback upon completion. |
Sample code
push.subscribe({
success: function(data) {
console.log("push.subscribe succeeded, result data=" + JSON.stringify(data));
},
fail: function(data, code) {
console.log("push.subscribe failed, result data=" + JSON.stringify(data) + ", code=" + code);
},
complete: function() {
console.log("push.subscribe completed");
}
}); Description
Unsubscribes from Push Kit. (This API is not recommended because regId is invalid after this API is called. You need to re-subscribe to Push Kit and obtain new regId.) If a user does not need to receive messages, you can call unsubscribe in the RPK and report that the regId has been deregistered on your server so that the regId will be excluded from receiving messages from your server.
If you send a large number of push messages to invalid regId, you will receive punishments including speed limit and service disabling.
OBJECT parameters
Parameter | Type | Mandatory/Optional | Description |
|---|---|---|---|
success | function | Optional | Callback upon success. |
fail | function | Optional | Failure callback. The cause of the failure is returned. |
complete | function | Optional | Callback upon completion. |
Sample code
push.unsubscribe({
success: function(data) {
console.log("push.unsubscribe succeeded, result data=" + JSON.stringify(data));
},
fail: function(data, code) {
console.log("push.unsubscribe failed, result data=" + JSON.stringify(data) + ", code=" + code);
},
complete: function() {
console.log("push.unsubscribe completed");
}
}); Description
Adds a push event callback. The payload content of a transparent push message can be received by the callback.
OBJECT parameters
Parameter | Type | Mandatory/Optional | Description |
|---|---|---|---|
callback | function | Mandatory | Push event callback. |
Returns
Parameter | Type | Description |
|---|---|---|
messageId | string | Message ID. |
data | string | Message content payload. |
Sample code
push.on({
callback: function(ret) {
console.log("received pass through message, ret=" + JSON.stringify(ret));
}
});