If the existing mini program APIs or events cannot meet your development requirements, you can extend them.
Mini Program calls native custom API
The client customizes the API and registers. Refer to Custom JSAPI to register your custom API.
Mini Program calls the API.
my.call('tinyToNative', { param1: 'p1aaa', param2: 'p2bbb' }, (result) => { console.log(result); my.showToast({ type: 'none', content: result.message, duration: 3000, }); })
Native applications send custom events to Mini Program
Mini Program registers the event.
my.on('nativeToTiny', (res) => { my.showToast({ type: 'none', content: JSON.stringify(res), duration: 3000, success: () => { }, fail: () => { }, complete: () => { } }); })The client sends the event.
Get the
viewControllerwhere the current Mini Program page is located, and call thecallHandlermethod to send the event.[self callHandler:@"nativeToTiny" data:@{@"key":@"value"} responseCallback:^(id responseData) { }];Parameter description::
Parameter
Description
handlerName
The name of the event monitored by the Mini Program.
data
The parameters passed by the client to the Mini Program.
callback
The call back processing block after the Mini Program executes the event.
Unregister custom event
If you no longer need custom events, please refer to Unregister custom events.