react-native - 使用 React Native 进行 Twilio 可编程聊天
问题描述
我正在尝试将 Twilio Chat 添加到我的反应原生项目中。我收到名称SyncError
和代码 0 的错误。我只是想确认它此时已连接。这是我的基本设置。
顶部导入
import {Client as Chat} from 'twilio-chat'
在我的班级里面
componentDidMount = async () => {
console.log(Chat);
const token = await AsyncStorage.getItem('auth-token');
axios.get(config.apiUrl + '/chat/details', { headers: { Authorization: token } })
.then(res => {
console.log(res);
Chat.create(res.data.twilioToken)
.then(client => {
console.log('client', client);
this.subscribeToAllChatClientEvents(client);
})
.catch(error => {
console.log('There was an error', error);
});
})
.catch(err => {
console.log(err);
})
}
该错误还提到了“未处理的承诺拒绝”,但我catch
在需要的地方包含了任何块。
谢谢你的帮助。
解决方案
令牌可能有问题。
根据我的经验,我从后端服务器获得了一个很好的令牌,并将其保存在 AsyncStorage 上。但是,过了一会儿,令牌不再起作用了。
每次我需要实例化 SDK 客户端时,我通过向服务器请求一个新的 twilio 令牌来解决它。
推荐阅读
- react-native - 在本机反应中获取输入值
- python - 在度中心性网络x值的字典中找到最大值的关键的更优雅的解决方案?
- javascript - 为什么只能将最后一个上下文推入数组
- angular - 我可以将 observable 作为函数参数传递吗?
- c - 我的 c 程序中这个奇怪的错误是什么?
- sqlite - 从 sqllite 数据库的 django 管理面板中删除一张表
- javascript - CRM WEB API 批处理
- dialogflow-es - 控制台操作中缺少 Alpha 用户
- python - 如何使用列表中的索引循环 tkinter 标签
- java - 如何添加 CROIMAGEACTIVITY 以加载个人资料照片?