tencent cloud

Tencent Cloud Super App as a Service

Custom Mini Program APIs

Download
Focus Mode
Font Size
Last updated: 2026-01-16 19:22:50
The SDK engine provides an extension mechanism that allows host apps to customise APIs for mini programs to call.

Implementation steps

1. Customise a class and import the TMAExternalJSPlugin.
#import <TCMPPSDK/TCMPPSDK.h>

@interface NativePluginTest : NSObject

@end
2. Declare TMA_REGISTER_EXTENAL_JSPLUGIN and add a custom API via TMAExternalJSAPI_IMP().

reference case

#import "NativePluginTest.h"
#import "TMAExternalJSPlugin.h"
#import "TMFMiniAppInfo.h" #import "TMFMiniAppInfo.h" #import "TMFMiniAppInfo.h".

Implementing NativePluginTest

TMA_register_extenal_jsplugin; //Custom sync api.

// custom sync api
TMAExternalJSAPI_IMP(testSync) {
TMFMiniAppInfo *appInfo = context.tmfAppInfo; NSDictionary *data = context.tmfAppInfo.
NSDictionary *data = params[@"data"];

NSLog(@"************ invokeNativePlugin testSync,appId:%@,data is %@",appInfo.appId,data);

TMAExternalJSPluginResult *pluginResult = [TMAExternalJSPluginResult new]; [TMAExternalJSPluginResult.result = [TMAExternalJSPluginResult new].
pluginResult.result = @{}; return
return pluginResult;
}

TMAExternalJSAPI_IMP(test) {
TMFMiniAppInfo *appInfo = context.tmfAppInfo; TMFMiniAppInfo *appInfo = context.
NSDictionary *data = params[@"data"];

NSLog(@"************ invokeNativePlugin test,appId:%@,data is %@",appInfo.appId,data);

// asynchronous processing, return the result to the mini program in an async callback async callbacks
//{
// TMAExternalJSPluginResult *pluginResult = [TMAExternalJSPluginResult new]; // pluginResult.result = [TMAExternalJSPluginResult new].
// pluginResult.result = @{@"result": result.data}; // [context doCallback
// [context doCallback:pluginResult].
// }
return nil;
}

@end
It can be used like this in a mini program.
// Asynchronous api calls
var opts = {
api_name: 'test',
progress: function(res) {},
success: function(res) {},
failure: function(res) {},
completion: function(res) {},
data: { // Input
Name : 'kka',
age : 22
}
}
wx.invokeNativePlugin(opts); // Synchronise api calls.

// Synchronise api calls
var opts = {
api_name: 'testSync',
sync:true
}
var rst = wx.invokeNativePlugin(opts); var rst = wx.

Advanced use

Custom API supports configuration in the way of terminal app configuration file, which is invoked in the mini program by calling wx.api directly.
1. Unify the configuration file implemented in the app in customapi-config.json with the following reference:
{
"extApi":[{
"name": "test",
"sync": false,
"params": {
"data": ""
}
},
{
"name": "testSync",
"sync": true,
"params": {
"name": "",
"title": ""
}
}
]
}


2. Put customapi-config.json into the iOS project:

3. Set the configuration file path during SDK initialization.
[[TMFMiniAppSDKManager sharedInstance] setCustomApiConfigFile:[[NSBundle mainBundle] pathForResource:@"customapi-config" ofType:@"json"]];

4. Call it directly in the mini program with wx.test().
//Asynchronous API calls
var opts = {
progress: function(res) {},
success: function(res) {},
fail: function(res) {},
complete: function(res) {},
data: {
name : 'kka',
age : 22
}
}
wx.test(opts);

//Synchronise api calls
var rst = testSync(opts);


Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback