Before you begin
- Register a QuickBlox account. This is a matter of a few minutes and you will be able to use this account to build your apps.
- Configure QuickBlox SDK for your app. Check out Setup page for more details.
- Create a user session to be able to use QuickBlox functionality. See Authentication page to learn how to do it.
Visit Key Concepts page to learn the most important QuickBlox concepts.
Connect to chat server
To connect to the chat server use the code snippet below.
Use QBChatDelegate to handle different connection states.
Connect to chat server with QuickBlox session token
In case, you authenticate with QuickBlox via Firebase, Facebook, or Custom Identity Provider, you should connect to the chat server with QuickBlox user session token and QuickBlox user ID.
As a result of successful authentication via Firebase, Facebook, or Custom Identity Provider, you receive a QuickBlox user session token and QuickBlox user ID. Use QuickBlox user session token as a password and QuickBlox user ID as a login to connect to the chat server.
Don’t use the Firebase/Facebook access token as a password to connect to the chat server. You will receive the following runtime error in this case: <failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/><text xml:lang='en'>Password not verified</text></failure>.
Disconnect from chat server
Disconnect from the chat server using the snippet below.
Enable auto-reconnect to chat
Auto-reconnect is turned off by default. If you want the SDK to automatically reconnect to the chat server when the connection is lost, just enable this option:
Once enabled, the SDK will handle reconnection automatically, no additional code needed.
Manage chat connections
To provide a seamless chat experience, our SDK manages connections to the chat server at an application-wide level. Thus, to handle offline messages correctly, use the disconnect() method when an app goes to the background and connect() method when an app goes to the foreground. As a result, the SDK will disconnect/connect the current user from the chat server when the app goes to the background/foreground mode.
Set connection settings
Use the settings below to configure the connection to the chat server.