Pubnub for chat in ios

There is project which have chat feature which is been done by using PubNub. I had gone through the tutorial provided by PubNub and had integrated the pubnub.framework and CocoaLumberjack in my project. And had added the coded as shown in this tutorial

My questions are:

  1. Do i have to create different channel to chat with the different friends? Or how the channel in the PubNub will work? I want to do only one-one chat. I don’t want to implement any group chats. As per my study from using PubNub for multi users chatting every user have their own channel. But in that case how can I load the unread message count or messages when I am offline.
  2. What is the process to install the PubNub server in my backend server? I am using backend as PHP Laravel.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

  1. you are free to create an unlimited number of channels, so for 1-1 chats, every user is subscribed to their own private channel. to chat with you, I publish a message to your private channel. here is a write-up that outlines this in more detail. for short periods of being offline (less than 10 mins), you can rely on the catch-up mechanism (make sure you configure this). for retrieving the actual messages while you were offline, you can use the history() function of Storage & Playback. retrieving only the count of unread messages requires logic on your end… perhaps keeping count of the number of messages published for each channel in your backend database, and then clients can make a REST call to your backend to retrieve this count.
  2. PubNub has a PHP SDK you can use… what do you plan on having your backend server do?

Method 2

@Alex is right and here is some more clarity on that:

Every user should have an inbound channel that they subscribe to and anyone that wants to invite them to a private chat publishes an invite message with the name of the new 1-1 chat channel, in that message. If the invited users accepts, that user will subscribe to the new 1-1 channel, else a decline message can be returned on the inviter user’s inbound channel.

For any channel that a user needs to know the number of messages missed while offline (or just not actively subscribed to a channel), you need to call history on those channels with the timetoken of the last received message on that channel. This will retrieve the messages and you can just get the size of the array of returned messages to display that unread message count.

There is no PubNub server to install. Your PHP server app/script will use the PubNub network in much the same way that your iOS client apps use it. There is just the PHP SDK that you have to download and requre:

You can think of both your server and your client apps as clients of the PubNub Network. Your PHP app will likely on publish messages on channel but not subscribe to channels, though. If you are thinking you need to subscribe to channels from your PHP app, please contact PubNub Support with details about your use case.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x