tencent cloud

最后更新时间:2025-12-19 20:16:29
iOS
最后更新时间: 2025-12-19 20:16:29

SDK 集成

1. 本文档说明在 TRTC SDK 项目中集成和使用 TEBeautyKit 库

SDK 使用

步骤一:集成 TEBeautyKit

1. 下载并解压 TRTCAdapter
2. TRTCAdapter.framework 添加到工程中。

3. 编辑 podfile 文件,添加下面的代码:
# 将S1-07替换成您购买的套餐
pod 'TEBeautyKit/S1-07', :podspec => 'https://mediacloud-76607.gzc.vod.tencent-cloud.com/TencentEffect/iOS/TEBeautyKit/latest/TEBeautyKit.podspec'
4. 执行pod install
5. 引入面板资源,点击下载资源包(beauty_panel.zip)后,引入主工程。

步骤二:鉴权

[TEBeautyKit setTELicense:@"your license" key:@"your key" completion:^(NSInteger authresult, NSString * _Nullable errorMsg) {
NSLog(@"----------result: %zd %@",authresult,errorMsg);
}];

步骤三:配置美颜素材路径

如果 json 文件中配置的素材是本地的,需要将美颜素材添加到工程中。
- (void)configPanel {
NSBundle *bundle = [NSBundle mainBundle];
NSString *beautyJsonPath = [bundle pathForResource:@"beauty" ofType:@"json"]; //美颜
NSString *lutJsonPath = [bundle pathForResource:@"lut" ofType:@"json"]; //滤镜
NSString *motion2dJsonPath = [bundle pathForResource:@"motion_2d" ofType:@"json"]; //2d贴纸
NSMutableArray *resArray = [[NSMutableArray alloc] init];
[resArray addObject:@{TEUI_BEAUTY : beautyJsonPath}];
[resArray addObject:@{TEUI_LUT : lutJsonPath}];
[resArray addObject:@{TEUI_MOTION_2D : motion2dJsonPath}];
/// 设置资源
[[TEUIConfig shareInstance] setTEPanelViewResources:resArray];
}

步骤四:初始化并添加 TEPanelView

- (void)addPanelView {
TEPanelView *tePanelView = [[TEPanelView alloc] init];
tePanelView.delegate = self;
[self.view addSubview:tePanelView];
[tePanelView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.bottom.mas_equalTo(self.view);
make.left.right.mas_equalTo(self.view);
make.height.mas_equalTo(230 + self.view.safeAreaInsets.bottom);
}];
}

步骤五:adapter 绑定美颜

/// 创建adapter对象
- (TEBeautyTRTCAdapter *)trtcAdapter {
if (!_trtcAdapter) {
_trtcAdapter = [[TEBeautyTRTCAdapter alloc] init];
}
return _trtcAdapter;
}
/// 绑定美颜
__weak __typeof(self)weakSelf = self;
[self.trtcAdapter bind:self.trtcCloud onCreatedXmaicApi:^(XMagic * _Nullable xmagicApi) {
__strong typeof(self) strongSelf = weakSelf;
strongSelf.teBeautyKit.xmagicApi = xmagicApi;
[strongSelf.teBeautyKit setLogLevel:YT_SDK_ERROR_LEVEL];
strongSelf.tePanelView.teBeautyKit = strongSelf.teBeautyKit;
[strongSelf.tePanelView setDefaultBeauty];
} onDestroyXmaicApi:^{
__strong typeof(self) strongSelf = weakSelf;
[strongSelf.teBeautyKit onDestroy];
strongSelf.teBeautyKit = nil;
}];

步骤六:参数变化通知 adapter

/// 通知adapter前后置摄像头,是否编码镜像
[self.trtcAdapter notifyCameraChanged:self.isFrontCamera isEncoderMirror:self.isEncoderMirror];
/// 通知adapter屏幕方向改变
[self.trtcAdapter setDeviceOrientation:currOrientation];

步骤七:解绑 adapter,销毁美颜

[self.trtcAdapter unbind];
self.trtcAdapter = nil;
本页内容是否解决了您的问题?
您也可以 联系销售 提交工单 以寻求帮助。

文档反馈