【2025年1月2日】关于腾讯云小程序平台更名为腾讯云超级应用服务的公告
控制台更新动态
Android SDK 更新动态
iOS SDK 更新动态
Flutter 更新动态
IDE 更新动态
基础库更新动态
//TCSAS#import <TCMPPSDK/TCMPPSDK.h>
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"tcsas-ios-configurations" ofType:@"json"];if(filePath) {TMAServerConfig *config = [[TMAServerConfig alloc] initWithFile:filePath];[[TMFMiniAppSDKManager sharedInstance] setConfiguration:config];}
[TMFMiniAppSDKManager sharedInstance].miniAppSdkDelegate = [MIniAppDemoSDKDelegateImpl sharedInstance];
// 通过小程序id打开小程序// Open the mini program through the mini program id// @param appID 小程序ID - Mini program ID// @param verType 指定打开的小程序类型 - The version type of mini program to open// @param scene 场景值 - scene value// @param firstPage 打开页面 - open the page// @param paramsStr 带入参数 - brings in parameters// @param parentVC 从哪个vc呼起 - Which vc to call from// @param completion 错误回调 - error callback- (void)startUpMiniAppWithAppID:(NSString *)appIDverType:(TMAVersionType)verTypescene:(TMAEntryScene)scenefirstPage:(NSString * _Nullable)firstPageparamsStr:(NSString * _Nullable)paramsStrparentVC:(UIViewController *)parentVCcompletion:(void (^)(NSError * _Nullable))completion;
名称 | 是否必填 | 类型 | 作用 |
appID | YES | NSString | 打开指定小程序的小程序 id |
verType | YES | TMAVersionType | 打开小程序的类型 |
scene | YES | TMAEntryScene | 打开小程序使用的场景值 |
firstPage | NO | NSString | 打开页面 |
paramsStr | NO | NSString | 打开传递参数 |
parentVC | YES | UIViewController | 从哪个 VC 呼起 |
completion | YES | block | 错误回调 |
[[TMFMiniAppSDKManager sharedInstance] startUpMiniAppWithAppID:info.appIdverType:TMAEntrySceneNonescene:TMAEntrySceneAIOEntryfirstPage:nilparamsStr:[NSString stringWithFormat:@"noServer=%@",noServerStr]parentVC:selfcompletion:^(NSError * _Nullable error) {}];
[[TMFMiniAppSDKManager sharedInstance] startUpMiniAppWithQRCodeWithParentVC:self completion:^(NSError * _Nullable err) {}];


- (NSString *)getAppScheme{return @"tcsas";}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {if ([[TMFMiniAppSDKManager sharedInstance] handleOpenUrl:url]){return YES;}return YES;}
[[TMFMiniAppSDKManager sharedInstance] searchAppletsWithName:@"" completion:^(NSArray<TMFAppletSearchInfo *> * _Nonnull result, NSError * _Nonnull aError) {}];
//获取最近打开的所有小程序信息///@return 小程序数组<TMFMiniAppInfo>- (NSArray *)loadAppletsFromCache;
NSArray *list = [[TMFMiniAppSDKManager sharedInstance] loadAppletsFromCache];self.recentList = [NSMutableArray arrayWithArray:list];if (self.demoList) {[self.demoList removeAllObjects];} else {self.demoList = [[NSMutableArray alloc] init];}[[TMFMiniAppSDKManager sharedInstance] searchAppletsWithName:@"" completion:^(NSArray<TMFAppletSearchInfo *> * _Nullable datas, NSError * _Nullable error) {[self.demoList addObjectsFromArray:datas];if (self.selectIndex == 0) {self.dataSource = self.demoList;}[self.tableView reloadData];}];


/*** @brief Superapp设置的当前语言 - Get current language set by the app* @return 格式 - format : "zh-Hans"*/- (NSString *)getCurrentLocalLanguage;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {NSString *language = @"en";if (indexPath.row == 0) {language = @"zh-Hans";} else if (indexPath.row == 1) {language = @"en";} else if (indexPath.row == 2) {language = @"fr";} else if (indexPath.row == 3) {language = @"id";}[[LanguageManager shared] setCurrentLanguage:language];/// 注意需要终止小程序[[TMFMiniAppSDKManager sharedInstance] terminateAllApplications];}
- (NSString *)getCurrentLocalLanguage {return [[LanguageManager shared] currentLanguage];}
- (NSString *)getAppUID {return [DemoUserInfo sharedInstance].userId;}
[[TMFMiniAppSDKManager sharedInstance] terminateAllApplications];

#pragma mark - 退出挽留 - Exit retention- (BOOL)shouldDetainUser:(TMFMiniAppInfo *)app;

// 点击胶囊按钮呼起面板 - Click the capsule button to call up the panel// 如果此方法不实现,则会调用showActionSheetWithTitle:cancelButtonTitle:cancelAction:otherButtonTitleAndActions:dismissBlock:presentingViewController: - If this method is not implemented, showActionSheetWithTitle:cancelButtonTitle:cancelAction:otherButtonTitleAndActions:dismissBlock:presentingViewController: will be called.// @param app 小程序信息 - Mini program information// @param cancelButtonTitle 取消标题 - cancel title// @param cancelAction 取消操作 - cancel the operation// @param otherButtonTitleAndActions 其他按钮及响应操作 - other buttons and response operations// @param dismissBlock 面板收起后需要执行的操作(一定要调用以保证功能正确!!!)- The operation that needs to be performed after the panel is closed (must be called to ensure correct function!!!)// @param parentVC 呼起面板的vc - calls up the vc of the panel- (void)showMoreButtonActionSheetWithApp:(TMFMiniAppInfo *)appcancelButtonTitle:(nullable NSString *)cancelButtonTitlecancelAction:(nullable dispatch_block_t)cancelActionotherButtonTitleAndActions:(nullable NSArray *)otherButtonTitleAndActionsdismissBlock:(nullable dispatch_block_t)dismissBlockparentVC:(UIViewController *)parentVC;

// Superapp可以自定义分享途径、决定展示顺序,目前使用在点击更多按钮、button组件(open-type="share")呼起的ActionSheet中// 1、默认渠道:QQ好友、QQ空间、微信、朋友圈(具体type参见MAUIDelegateShareViewType),由开发商决定,Superapp只能更改展示顺序// 2、自定义分享渠道:Superapp自定义(type填MAUIDelegateShareViewTypeCustomizedShare,自定义MAShareTarget,建议大于100,在小程序页面中onShareAppMessage 回传分享内容,统一走shareMessageWithModel由Superapp根据ShareTarget来分别处理)// 3、自定义事件:Superapp自定义(type填MAUIDelegateShareViewTypeCustomizedAction)// 以上三种渠道展示顺序支持混排///// The host App can customize the sharing path and determine the display order. It is currently used in the ActionSheet called up by clicking the more button or button component (open-type="share")// 1. Default channels: QQ Friends, QQ Space, WeChat, Moments (for specific types, see MAUIDelegateShareViewType), decided by the developer, the host App can only change the display order// 2. Customized sharing channel: Host App customization (type fills in MAUIDelegateShareViewTypeCustomizedShare, custom MAShareTarget, it is recommended to be greater than 100, in the mini program page, onShareAppMessage returns the sharing content, use shareMessageWithModel uniformly, and the host handles it separately according to ShareTarget)// 3. Custom event processing: Host App customization (type fills in MAUIDelegateShareViewTypeCustomizedAction)// The display order of the above three channels- (NSArray<TMASheetItemInfo *> *)customizedConfigForShare;
- (NSArray<TMASheetItemInfo *> *)customizedConfigForShare {NSMutableArray *arrays = [[NSMutableArray alloc] init];TMASheetItemInfo *item1 = [[TMASheetItemInfo alloc] initWithTitle:@"More sharing" type:MAUIDelegateShareViewTypeCustomizedShare shareTarget:100 shareKey:@"my"];item1.icon = [UIImage imageNamed:@"icon_moreOperation_shareChat"];[arrays addObject:item1];TMASheetItemInfo *item2 = [[TMASheetItemInfo alloc] initWithTitle:@"click" type:MAUIDelegateShareViewTypeCustomizedAction action:^(TMASheetActionParams * _Nullable params) {NSLog(@"click 点击");}];item2.icon = [UIImage imageNamed:@"icon_moreOperation_collect"];[arrays addObject:item2];return arrays;}

- (void)customizedConfigForMoreButtonActions:(NSMutableArray *)moreButtonTitleAndActions withApp:(TMFMiniAppInfo *)app{/*//增加一个自定义分享项TMASheetItemInfo *item = [[TMASheetItemInfo alloc] initWithTitle:@"Share" type:MAUIDelegateShareViewTypeCustomizedShare shareTarget:100 shareKey:@"my"];item.icon = [UIImage imageNamed:@"icon_moreOperation_shareChat"];[moreButtonTitleAndActions addObject:item];*//*//删除复制链接菜单NSMutableArray *newArrays = [[NSMutableArray alloc] initWithCapacity:moreButtonTitleAndActions.count];for (TMASheetItemInfo *item in moreButtonTitleAndActions) {if(item.type != MAUIDelegateShareViewTypeCopyLink) {[newArrays addObject:item];}}[moreButtonTitleAndActions removeAllObjects];[moreButtonTitleAndActions addObjectsFromArray:newArrays];*/}
小程序 API | TMFMiniAppSDKDelegate 方法 |
wx.showLoading |
|
wx.hideLoading |
|
wx.showToast |
|
wx.hideToast |
|
wx.showActionSheet (actionSheetType = 0) |
|
wx.showActionSheet (actionSheetType = 1) |
|
wx.showModal |
|
/// 打印Log/// @param level log级别,参考PLTLogLevel/// @param msg log信息- (void)log:(MALogLevel)level msg:(NSString *)msg;
- (NSString *)getAppTheme{return @"dark";}


- (NSString *)getAppScheme{return @"tcsas";}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {if ([[TMFMiniAppSDKManager sharedInstance] handleOpenUrl:url]){return YES;}return YES;}
#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": ""}}]}

[[TMFMiniAppSDKManager sharedInstance] setCustomApiConfigFile:[[NSBundle mainBundle] pathForResource:@"customapi-config" ofType:@"json"]];
//异步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);
#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;}//接收小程序端的调用事件进行处理- (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];// 把结果返回给小程序端TMAExternalJSPluginResult *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";// 组装数据 发送事件NSString *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, // native传递的参数}
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)}})
文档反馈