需要先做好准备工作,依照文档把接入步骤做完,地址:https://open.douyin.com/platform/doc/6850392241442408456
具体代码下载地址
https://github.com/xwh123456/react-native-DouYin
----安卓集成---
在此处加入这两行
implementation 'com.bytedance.ies.ugc.aweme:opensdk-china-external:0.1.3.0'
implementation 'com.bytedance.ies.ugc.aweme:opensdk-common:0.1.3.0'
在git上下载放在该目录下分别加入这几处
import com.bytedance.sdk.open.douyin.DouYinOpenApiFactory;
import com.bytedance.sdk.open.douyin.DouYinOpenConfig;
packages.add(new Douyin());
DouYinOpenApiFactory.init(new DouYinOpenConfig(clientkey));
在JS代码中加入
const { DouYin } = NativeModules;
DouYin.sendAuthRequest('user_info', '', (res: any) => {
console.log(res);
})
该处是发送请求然后监听返回值,componentDidMount中
DeviceEventEmitter.addListener('DouYin_Resp', resp => {
// emitter.emit('DouYin_Resp', resp);
console.log(resp);
Toast.info(JSON.stringify(resp));
if (resp.authCode) {
this.handleDyOauth(resp.authCode);
}
});
---ios集成---
ios的集成步骤请看官方文档 https://open.douyin.com/platform/doc集成工作完成后把两个文件拖到ios的根目录
需要主动注册
在JS代码中就可以调用
const { dyModule } = NativeModules;
dyModule.sendDyRequest('','',(res)=>{
console.log(res);
if(res){
this.handleDyOauth(res);
}
})
如果有疑问可以留言,最好点一个star,谢谢