Announcement: Tencent Cloud Mini Program Platform Renamed to Tencent Cloud Super App as a Service on January 2, 2025
Console Updates
Android SDK Updates
iOS SDK Updates
Flutter SDK Updates
IDE Updates
Base Library Updates
#import "QMATestView.h"#import "TMAExternalJSPlugin.h"@interface QMATestView () <TMAExternalElementView>@end@implementation QMATestView {UILabel *_textLabel;UIButton *_clickButton;id<TMAExternalJSContextProtocol> _context;}TMARegisterExternalElement(maTestView);+ (UIView *)createWithParams:(NSDictionary *)params context:(id<TMAExternalJSContextProtocol>)context {QMATestView *testView = [[QMATestView alloc] initWithFrame:CGRectZero];NSDictionary *testViewParams = QQ_Dict_DictValue(params, @"params");[testView setText:QQ_Dict_StringValue(testViewParams, @"text")];testView->_context = context;return testView;}//Handle events called from the mini program side- (void)operateWithParams:(NSDictionary *)param context:(id<TMAExternalJSContextProtocol>)context {NSDictionary *data = QQ_Dict_DictValue(param, @"data");NSDictionary *params1 = QQ_Dict_DictValue(data, @"params1");NSInteger age = [QQ_Dict_NumberValue(params1, @"age") integerValue];NSString *name = QQ_Dict_StringValue(params1, @"name");qq_weakify(self);[MAUtils executeOnThread:[NSThread mainThread] block:^{qq_strongify(self);if (self) {self->_textLabel.text = [NSString stringWithFormat:@"name = %@ , age = %ld",name,(long)age];// Return the result to the mini program sideTMAExternalJSPluginResult *result = [TMAExternalJSPluginResult new];result.result = @{@"result":@"success"};[context doCallback:result];}}];}
_context = context;
- (void)onClickButton:(UIButton *)button {_textLabel.text = @"What do you want me to do";//Assemble data and send the eventNSString *data = [MAUtils JSONStringify:@{@"externalElementId":_elementId,@"type": @"elvisgao callback"}];[_context doSubscribe:kTMAOnExternalElementEvent data:data];}
<external-elementid="comp1"type="maTestView"_insert2WebLayerstyle="width: 200px;height: 100px;"bindexternalelementevent="handleEvent"></external-element>
{target,currentTarget,timeStamp,touches,detail, // Parameters passed from native side}
this.ctx = wx.createExternalElementContext('comp1');
this.ctx.call({params1: {name: 'name1',age: 11},params2: {name: 'name2',age: 22},success: (e) => {console.log('====operate success=====', e)},fail: (e) => {console.log('====operate fail=====', e)},complete: (e) => {console.log('====operate complete=====', e)}})
Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback