tencent cloud

腾讯云超级应用服务

其他

Download
聚焦模式
字号
最后更新时间: 2026-07-02 20:13:39

Superapp 相关接口

/**
* @brief Superapp应用名称 - Superapp name
* 此 API 提供用于文本显示的superapp名称 - Mainly used for copywriting prompts
*/
- (NSString *)appName;

/**
* @briefSuperapp版本 - Superapp version
* @return 返回的是小写字符串,例如1.0.0 - returns a lowercase string, such as 1.0.0
*/
- (NSString *)getAppVersion;

/**
* @brief 网络状态 - The network status
*/

- (TMANetWorkStatus)getAppNetworkStatus;

/**
* @brief 机型信息 - The Model information
*/
- (NSString *)getAppIPhoneModel;

/**
* @brief 设备信息 - The device information
* @return 格式 - format : {@"brand":@"iPhone",@"model":@"iPhone 11<iPhone12,1>",@"system":@"ios",@"platform":@"iOS 16.4.1"}
*/
- (NSDictionary *)getAppDeviceInfo;
/**
* @brief Superapp基础信息 - Get basic information of the superapp
* @return 格式 - format : {@"SDKVersion":@"2.32.2",@"model":@"iPhone 11<iPhone12,1>",@"system":@"ios",@"platform":@"iOS 16.4.1"}
*/
- (NSDictionary *)getAppBaseInfo;

/**
* @brief Superapp设置的当前语言 - Get current language set by the Superapp
* @return 格式 - format : "zh-Hans"
*/
- (NSString *)getCurrentLocalLanguage;


/**
* @brief Superapp设置的当前主题 如果不实现此方法 那么getAppBaseInfo中返回的theme为系统主题 - The current theme set by the superapp. If this method is not implemented, the theme returned in getAppBaseInfo will be the system theme.
*/
- (NSString *)getAppTheme;

/**
* @brief 剪贴板频控 - Clipboard frequency control
*/
- (NSNumber *)getClipboardInterval

// 小程序最多保活的个数,默认是3
// The maximum number of mini programs that can be kept alive, the default is 3
- (NSInteger)maxMiniAppKeepAliveCount;

// Superapp URL Scheme
// Set the superapp URL Scheme
- (NSString *)getAppScheme;

截屏、录屏事件和添加水印

- (void)applet:(TMFMiniAppInfo *)appletInfo screenCaptureStatusChanged:(BOOL)isCapture atPagePath:(NSString *)pagePath;

- (void)appletDidTakeScreenshot:(TMFMiniAppInfo *)appletInfo atPagePath:(NSString *)pagePath;

- (nullable UIView *)appletCustomizeWatermarkView:(TMFMiniAppInfo *)appletInfo;

web-view 组件中特殊链接处理

对于 web-view 组件页面中要处理的特殊链接透传至 superapp,由 superapp 进行处理。
// web-view组件中跳转非http/https时触发,用于处理web-view组件中特殊url的情况,比如打开其它App - Triggered when redirecting to non-http/https in the web-view component. Used to handle special URLs in the web-view component, such as opening other apps.
// @param app {TMFMiniAppInfo} web-view组件所在的小程序信息 - Mini-program information where the web-view component is located
// @param url {NSURL} 要打开的url - The url to open
// @return 是否拦截处理 - Whether to intercept processing
- (BOOL)webViewCustomUrlLoading:(TMFMiniAppInfo *)app url:(NSURL *)url {
NSLog(@"webViewCustomUrlLoading:%@,appid:%@",[url absoluteString],app.appId);
if ([[UIApplication sharedApplication] canOpenURL:url]) {
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
if (success) {
NSLog(@"webViewCustomUrlLoading:%@,appid:%@, open sucess",[url absoluteString],app.appId);
}
}];
} else {
[[UIApplication sharedApplication] openURL:url];
}
return YES;
} else {
NSLog(@"webViewCustomUrlLoading:%@,appid:%@,cann't open!!!",[url absoluteString],app.appId);
}
return NO;
}

iOS18及以上系统使用 HTTP 资源兼容

Superapp 可以配置关闭所有小程序调试功能,包括小程序调试开关及远程调试。
//TMFMiniAppSDKDelegate protocol
- (NSString *)stringWithConfigKey:(NSString *)key {
if([key isEqualToString:TMA_SK_MINIAPP_ATS_Allow_Arbitrary_Loads]) {
return @"1";
}
return nil;
}

禁用小程序调试相关功能

Superapp 可以通过代理接口设置,禁用所有小程序调试相关功能,包括小程序调试入口及远程调试。

//TMFMiniAppSDKDelegate protocol
- (NSString *)stringWithConfigKey:(NSString *)key {
if([key isEqualToString:TMA_SK_MINIAPP_EnableDebug_Allow]) {
return @"0";
}
return nil;
}

iOS26及以上修改导航栏按钮显示样式

iOS26及以上系统默认导航栏按钮为毛玻璃显示效果,superapp 可以通过代理接口设置,关闭该效果显示,保持与之前版本一致。

//TMFMiniAppSDKDelegate protocol
- (NSString *)stringWithConfigKey:(NSString *)key {
if([key isEqualToString:TMA_SK_MINIAPP_NavigationItem_HidesSharedBackground]) {
return @"1";
}
return nil;
}

自定义 web-view 组件错误页面

web-view 组件加载不在白名单内的域名时,SDK 会展示一张错误页。从 2.3.9 起支持替换为自定义页面(未配置时自动回落到内置页)。
用法
实现 TMFMiniAppSDKDelegate 的 stringWithConfigKey:,返回自定义错误页的本地绝对路径:

- (NSString *)stringWithConfigKey:(NSString *)key {
if ([key isEqualToString:TMA_SK_MINIAPP_WebView_DomainError_PagePath]) {
return [[NSBundle mainBundle] pathForResource:@"my_error_page"
ofType:@"html"
inDirectory:@"Resource/jssdk"];
}
return nil;
}
错误页通过 URL 参数 ?msg=<URL-encoded message> 拿到被拦截的域名/文案,前端 decode 后展示即可:

<script>
var msg = decodeURIComponent(new URLSearchParams(location.search).get('msg') || '');
document.getElementById('tip').innerText = msg;
</script>
注意:
必须是本地文件绝对路径,不支持远程 URL。
返回 nil、空字符串或文件不可读时,自动回落到内置错误页面。

小游戏动态注入 JS

支持 superapp 在小游戏冷启动时,向小游戏注入一段自定义前置 JS。注入时机在基础库加载完成之后、游戏代码 game.js 执行之前,可用于预置全局变量、Mock 接口或埋点。
用法
实现 TMFMiniAppSDKDelegate 的以下方法,返回要注入的 JS(返回 nil/空串表示不注入):

- (nullable NSString *)miniGameJSPreludeForAppInfo:(TMFMiniAppInfo *)appInfo {
// 可按 appInfo.appId 区分不同小游戏
return @"(function(){ globalThis.__HOST_ENV__ = { channel: 'demo' }; })();";
}
注意:
仅冷启动调用一次,热启动不再触发;仅对小游戏生效。
与 game.js 共享全局命名空间,建议用 IIFE (function(){ ... })(); 包裹。
调用时 wx / qq API 已可用;注入 JS 抛异常不会阻塞游戏加载。


帮助和支持

本页内容是否解决了您的问题?

填写满意度调查问卷,共创更好文档体验。

文档反馈