客户端发送通知到卡片

卡片侧通过 JSAPI 注册通知监听

引入依赖

const mp = requireModule("mpaas_jsapi");

postNotification

发送通知。

mp.postNotification(
  {
    name:'TEST_EVENT',
    data: {
      hello: 'hello world'
    }
  },
  res=>{
    
  }
);

addNotifyListener

注册通知在生命周期 didAppear 中。

   didAppear() {
        mp.addNotifyListener(
            {
                name: 'TEST_EVENT'
            },
            res => {
                this.clientToCube(res)
            }
        )
    },

removeNotifyListener

移除通知。

didDisappear() {
        mp.removeNotifyListener(
            {
                name: 'TEST_EVENT'
            },
            res => {
                console.info(JSON.stringify(res))
            }
        )
    },
说明

客户端做了校验,调用 MPCube.recycleCard 后会自动释放通知监听。

客户端发送通知

Android

MPCube.postNotification(String notifyName,JSONObject notifyParams);

iOS

[[NSNotificationCenter defaultCenter] postNotificationName:notifyName object:nil userInfo:notifyParams];

鸿蒙

MPCardNotifyCenter.get().postNotify(notifyName:string, params:object, instanceId:string, callback:IFalconCallback)