#import <TCMPPSDK/TCMPPSDK.h>@interface NativePluginTest : NSObject@end
#import "NativePluginTest.h"#import <TCMPPSDK/TCMPPSDK.h>@implementation NativePluginTestTMA_REGISTER_EXTENAL_JSPLUGIN;//自定义同步 apiTMAExternalJSAPI_IMP(testSync) {TMFMiniAppInfo *appInfo = context.tmfAppInfo;NSDictionary *data = params[@"data"];NSLog(@"************ invokeNativePlugin testSync,appId:%@,data is %@",appInfo.appId, data);TMAExternalJSPluginResult *pluginResult = [TMAExternalJSPluginResult new];pluginResult.result = @{};return pluginResult;}TMAExternalJSAPI_IMP(test) {TMFMiniAppInfo *appInfo = context.tmfAppInfo;NSDictionary *data = params[@"data"];NSLog(@"************ invokeNativePlugin test,appId:%@,data is %@",appInfo.appId, data);//异步处理,在异步回调中把结果返回给小程序 async callback//{// TMAExternalJSPluginResult *pluginResult = [TMAExternalJSPluginResult new];// pluginResult.result = @{@"result" : result.data};// [context doCallback:pluginResult];// }return nil;}@end
//异步api调用var opts = {api_name: 'test',success: function(res) {},fail: function(res) {},complete: function(res) {},data: { // 入参name : 'kka',age : 22}}wx.invokeNativePlugin(opts);//同步api调用var opts = {api_name: 'testSync',sync:true}var rst = wx.invokeNativePlugin(opts);
{"extApi":[{"name": "test","sync": false,"params": {"data": ""}},{"name": "testSync","sync": true,"params": {"name": "","title": ""}}]}
//异步api调用var opts = {success: function(res) {},fail: function(res) {},complete: function(res) {},data: {name : 'kka',age : 22}}wx.test(opts);//同步api调用var rst = testSync(opts);
本页内容是否解决了您的问题?