Quickblox one to one chat connection lost

瘦欲@ 提交于 2019-12-24 04:13:31

问题


I have developed chat application using Quickblox SDK version 0.8.1. Sometimes app loses chat connection to the server so can not send message or receive message even in same chat page. I do have to reload every time this happens even sometimes it does not re-connect. So can any body help me with this.


回答1:


To reconnect to Chat please do:

iOS way

- (void)chatDidFailWithError:(int)code
{
    // reconnect
    [[QBChat instance] loginWithUser:[LocalStorageController shared].qbUser];
}

Android way (SDK 1.1 version)

// initialize SMACK
SmackAndroid.init(this);

final QBUser user = new QBUser("garry", "garry2892pass");
user.setId(4234);
QBChatService.getInstance().loginWithUser(user, LoginActivity.this);


@Override
public void onLoginSuccess() {
    Log.d(TAG, "success when login");
}

@Override
public void onLoginError() {
    Log.e(TAG, "error when login");
}

@Override
public void onDisconnect() {
    Log.d(TAG, "disconnect when login");

    // Relogin here
}

@Override
public void onDisconnectOnError(Exception exc) {
    Log.e(TAG, "disconnect error when login", exc);

    // Relogin here
}

More info here http://quickblox.com/developers/Android_XMPP_Chat_Sample

Just update Android SDK to 1.1 here http://quickblox.com/developers/Android#Download_Android_SDK




回答2:


Use latest version of quickblox. Current version is 1.1.

You have to send presence after login with timeer according to this documentation. http://quickblox.com/developers/Android_XMPP_Chat_Sample

After login

QBChatService.getInstance().startAutoSendPresence(60);

Hope this will solve.




回答3:


Use this way when using Quickblox SDK 2.0

ConnectionListener connectionListener = new ConnectionListener() {
@Override
public void connected(XMPPConnection connection) {

}

@Override
public void authenticated(XMPPConnection connection) {

}

@Override
public void connectionClosed() {

}

@Override
public void connectionClosedOnError(Exception e) {
    // connection closed on error. It will be established soon
}

@Override
public void reconnectingIn(int seconds) {

}

@Override
public void reconnectionSuccessful() {

}

@Override
public void reconnectionFailed(Exception e) {

}
};



QBChatService.getInstance().addConnectionListener(connectionListener);


来源:https://stackoverflow.com/questions/21276097/quickblox-one-to-one-chat-connection-lost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!