最近我更新了我的应用以支持最近的version twilio chat 0.11.1。之后,当我调用currentChannel.getMessages()时,它返回null。 我喜欢
Channels channelsObject = basicClient.getIpMessagingClient
channelsObject.getChannel(channelId, new CallbackListener<Channel>() {
@Override
public void onSuccess(final Channel channel) {
currentChannel = channel;
setupRecyclerView();
}
});
private void setupRecyclerView() {
currentChannel.addListener(ChatFragment.this);
currentChannel.synchronize(new com.twilio.chat.CallbackListener<Channel>() {
@Override
public void onError(ErrorInfo errorInfo) {
Application.get().logErrorInfo("Channel sync failed", errorInfo);
}
@Override
public void onSuccess(Channel result) {
logger.d("Channel sync success for " + result.getFriendlyName());
}
});
Messages messagesObject = currentChannel.getMessages();
我收到了像
这样的警告 | WARNING | ChatUtils(native) | ListenerWrapper default onSuccess() not found
| WARNING | Channel(native) | No messages available, maybe you forgot to synchronize the channel?
答案 0 :(得分:1)
没有可用的消息,您可能忘记同步频道了吗?
这正是发生的事情。仅当您收到CallbackListener.onSuccess()
回调时,频道才会同步。它是异步执行的,并且在该回调触发之前执行getMessages()
调用。
currentChannel.synchronize(new com.twilio.chat.CallbackListener<Channel>() {
@Override
public void onError(ErrorInfo errorInfo) {
Application.get().logErrorInfo("Channel sync failed", errorInfo);
}
@Override
public void onSuccess(Channel result) {
logger.d("Channel sync success for " + result.getFriendlyName() + " now can get messages and members objects");
Messages messagesObject = result.getMessages();
// should be non-null now
}
});