Client Sends Notification to Card
Updated at:
Register a notification listener on the card side using JSAPI
Import dependencies
const mp = requireModule("mpaas_jsapi");
postNotification
Send a notification from the card to the client.
mp.postNotification(
{
name:'TEST_EVENT',
data: {
hello: 'hello world'
}
},
res=>{
}
);
addNotifyListener
Register a notification listener in the didAppear lifecycle.
didAppear() {
mp.addNotifyListener(
{
name: 'TEST_EVENT'
},
res => {
this.clientToCube(res)
}
)
},
removeNotifyListener
Remove a notification listener when the card disappears.
didDisappear() {
mp.removeNotifyListener(
{
name: 'TEST_EVENT'
},
res => {
console.info(JSON.stringify(res))
}
)
},
Note
The client performs verification, and the notification listener is automatically released when MPCube.recycleCard is called.
Client sends notification
Android
MPCube.postNotification(String notifyName,JSONObject notifyParams);
iOS
[[NSNotificationCenter defaultCenter] postNotificationName:notifyName object:nil userInfo:notifyParams];
HarmonyOS
MPCardNotifyCenter.get().postNotify(notifyName:string, params:object, instanceId:string, callback:IFalconCallback)
Is this page helpful?