All Products
Search
Document Center

Unregister custom event

Last Updated: Apr 06, 2021

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.
       
    1. const call = my.call('tinyToNative', {
    2. param1: 'p1aaa',
    3. param2: 'p2bbb'
    4. }, (result) => {
    5. console.log(result);
    6. my.showToast({
    7. type: 'none',
    8. content: result.message,
    9. duration: 3000,
    10. });
    11. })

The method to unregister is as follows:

 
  1. //Unregister
  2. call.remove();
  3. call = undefined;

Native App sends custom events to mini program

The original operation steps are as follows:

  1. Register the event in mini program:
       
    1. const on = my.on('www',()=>{
    2. my.alert({
    3. title: '1212',
    4. content: '123',
    5. buttonText: '123123',
    6. success: () => {
    7. },
    8. fail: () => {
    9. },
    10. complete: () => {
    11. }
    12. });
    13. })
  2. Client sends events.
    Get the viewController where the current mini program page is located, and call the callHandler method to send events.
       
    1. [self callHandler:@"nativeToTiny" data:@{@"key":@"value"} responseCallback:^(id responseData) {
    2. }];

The method to unregister is as follows:

 
  1. on.remove();
  2. 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.