iOS
SDK 集成
1. 集成腾讯特效 SDK,请参考 TRTC SDK 集成腾讯特效。
2. 本文档说明在 TRTC SDK 项目中集成和使用 TEBeautyKit 库。
3. 参考 demo。
SDK 使用
步骤一:集成 TEBeautyKit
1. 下载并解压 TEBeautyKit。
2. 下载并解压 TRTCAdapter。
3. 把 TEBeautyKit 文件夹拷贝到自己的工程中,和 podfile 同级目录。
4. 把
TRTCAdapter.framework
添加到工程中。
5. 编辑 podfile 文件,添加下面的代码:
pod 'TEBeautyKit',:path => 'TEBeautyKit/TEBeautyKit.podspec'
6. 执行
pod install
。步骤二:鉴权
[TEBeautyKit setTELicense:@"your license" key:@"your key" completion:^(NSInteger authresult, NSString * _Nullable errorMsg) {NSLog(@"----------result: %zd %@",authresult,errorMsg);}];
步骤三:配置美颜素材路径
如果 json 文件中配置的素材是本地的,需要将美颜素材添加到工程中。
- (void)initBeautyJson{[[TEUIConfig shareInstance] setPanelLevel:S1_07];//根据美颜套餐选择}
步骤四:初始化并添加 TEPanelView
-(TEPanelView *)tePanelView{if (!_tePanelView) {_tePanelView = [[TEPanelView alloc] init:nil comboType:nil];_tePanelView.delegate = self;}return _tePanelView;}[self.view addSubview:self.tePanelView];[self.tePanelView mas_makeConstraints:^(MASConstraintMaker *make) {make.width.mas_equalTo(self.view);make.centerX.mas_equalTo(self.view);make.height.mas_equalTo(250);make.bottom.mas_equalTo(self.view.mas_bottom);}];
步骤五: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;