All Products
Search
Document Center

Mobile Platform as a Service:Unregister custom event

Last Updated:Feb 03, 2023

In the process of developing mPaaS Mini Program, if the existing Mini Program APIs or events cannot meet the development needs, you can also extend them by yourself; when these custom APIs or events are not needed, you can also unregister them.

Mini Program calls native custom API

The original operation steps are as follows:

  1. Customize the APIs and registers them in client.

    See Custom JSAPI to register your custom API.
  2. Mini program calls the API.
     const call = my.call('tinyToNative', {
       param1: 'p1aaa',
       param2: 'p2bbb'
     }, (result) => {
       console.log(result);
       my.showToast({
         type: 'none',
         content: result.message,
         duration: 3000,
       });
     })

The method to unregister is as follows:

    //Unregister
    call.remove();
    call = undefined;

Native App sends custom events to mini program

The original operation steps are as follows:

  1. Register the event in mini program:
     const on = my.on('www',()=>{
           my.alert({
             title: '1212',
             content: '123',
             buttonText: '123123',
             success: () => {
             },
             fail: () => {
             },
             complete: () => {
             }
           });
     })
  2. Client sends events.

    Get the viewController where the current mini program page is located, and call the callHandler method to send events.
    [self callHandler:@"nativeToTiny" data:@{@"key":@"value"} responseCallback:^(id responseData) {
    }];

The method to unregister is as follows:

    on.remove();
    on = undefined;

Parameter description:

Parameter Description
handlerName The name of the event monitored by the mini program.
data The parameter passed by the client to the mini program.
callback After the execution in mini program, call back processes the block.