#import <TCMPPSDK/TCMPPSDK.h>@interface NativePluginTest : NSObject@end
#import "NativePluginTest.h"#import "TMAExternalJSPlugin.h"#import "TMFMiniAppInfo.h" #import "TMFMiniAppInfo.h" #import "TMFMiniAppInfo.h".Implementing NativePluginTestTMA_register_extenal_jsplugin; //Custom sync api.// custom sync apiTMAExternalJSAPI_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 = @{}; returnreturn 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
// Asynchronous api callsvar opts = {api_name: 'test',success: function(res) {},failure: function(res) {},completion: function(res) {},data: { // InputName : 'kka',age : 22}}wx.invokeNativePlugin(opts); // Synchronise api calls.// Synchronise api callsvar opts = {api_name: 'testSync',sync:true}var rst = wx.invokeNativePlugin(opts); var rst = wx.
{"extApi":[{"name": "test","sync": false,"params": {"data": ""}},{"name": "testSync","sync": true,"params": {"name": "","title": ""}}]}
//Asynchronous API callsvar opts = {success: function(res) {},fail: function(res) {},complete: function(res) {},data: {name : 'kka',age : 22}}wx.test(opts);//Synchronise api callsvar rst = testSync(opts);
Was this page helpful?