Introduction
This tutorial will cover how to set up real-time updates for your application using Applozic SDK integrations and leverage the power of the pub-sub messaging pattern. You will learn how to: Subscribe/unsubscribe to topics and handle callbacks. Setup typing status indicators in your 1-to-1 and group chats. As a starting point for this tutorial, we are going to consider that you already have a working application and have implemented one of the Applozic Chat SDKs. You can follow these tutorial articles in case you want to set up your application with the iOS Chat SDK or iOS Voice and Video SDK offered by Applozic. If you face any difficulties while following this tutorial, you can contact us at support@applozic.com.
Connecting to publish
In order for a subscriber to receive messages on a topic, it needs to be subscribed and also needs a custom security policy to allow the topic to deliver messages to the queue. The following code handles both of these for you, without you ever having to deal with the details around building that custom policy.
Disconnecting from publish
If you want a subscriber to stop receiving messages on a topic, you can disconnect using the following code.
Handling the delegate callbacks
For handling real-time updates you need to:
- Implement the delegate ApplozicUpdatesDelegate.
- Implement the callbacks in Appdelegate and in your ViewController file
Setting up Typing Status Indicator
Typing indicators allow you to indicate if users are typing messages in a 1-to-1 or group chat. You can trigger a typing event when a user starts typing a message and this will let the user publish their typing status to anyone who has subscribed for the same.
Sending typing status
You can publish your typing status using the code given below.
Call the above method once a user starts typing in textViewDidChange or stops typing in textViewDidEndEditing.
Argument | Type | Description |
---|---|---|
recieverUserId | String | Pass recieverUserId in case of 1-to-1 typing status and pass channelKey as nil |
channelKey | NSNumber | Pass channelKey in case of group/channel typing status and pass recieverUserId as nil |
isTypingStarted | Bool | Pass true or YES in case user started typing Pass false or NO in case user stopped typing |
Subscribing to typing status
Unsubscribing to typing status
Conclusion
We began this article by discussing how to enable real-time updates in your application by leveraging Applozic SDKs.
A few key features that we wanted to implement were how to subscribe/unsubscribe from topics and handle callbacks and also how to set up typing status indicators in your 1-to-1 and group chats.
As we end this tutorial, you should be all set to send and receive real-time updates within your application.