If the default APIs and events do not meet your needs when you develop mPaaS Mini Programs, you can create custom extensions. You can also unregister these custom APIs and events when they are no longer needed.
Call a native custom API from a Mini Program
Original procedure:
Customize and register the API on the client.
For more information about how to register your custom API, see Custom JSAPI.
Call the API from the Mini Program.
const call = my.call('tinyToNative', { param1: 'p1aaa', param2: 'p2bbb' }, (result) => { console.log(result); my.showToast({ type: 'none', content: result.message, duration: 3000, }); })
The following describes the method for canceling the registration:
// Unregister
call.remove();
call = undefined;Send a custom event from a native application to a Mini Program
Original procedure:
Register the event in the Mini Program:
const on = my.on('www',()=>{ my.alert({ title: '1212', content: '123', buttonText: '123123', success: () => { }, fail: () => { }, complete: () => { } }); })Send the event from the client.
Obtain the
viewControllerof the current Mini Program page. Then, call thecallHandlermethod to send the event.[self callHandler:@"nativeToTiny" data:@{@"key":@"value"} responseCallback:^(id responseData) { }];
Follow this method to cancel the registration:
on.remove();
on = undefined;Parameters:
Parameter | Description |
handlerName | The name of the event that the Mini Program listens for. |
data | The parameters passed from the client to the Mini Program. |
callback | The callback block that is processed after the Mini Program completes execution. |