All Products
Search
Document Center

Mobile Platform as a Service:Custom APIs

Last Updated:Mar 13, 2025

If the existing mini program APIs or events cannot meet your development requirements, you can extend them.

Mini Program calls native custom API

  1. The client customizes the API and registers. Refer to Custom JSAPI to register your custom API.

  2. 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

  1. Mini Program registers the event.

    my.on('nativeToTiny', (res) => {
    my.showToast({
     type: 'none',
     content: JSON.stringify(res),
     duration: 3000,
     success: () => {
    
     },
     fail: () => {
    
     },
     complete: () => {
    
     }
    });
    })
  2. The client sends the event.

    Get the viewController where the current Mini Program page is located, and call the callHandler method 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.