Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Text or chat in your app

so far i know that i need UITextfield UITextView UIButton ,but which framework i have to use ,and how to save it into parse or add users in the chat

2 Answers

Robert Bojor
PLUS
Robert Bojor
Courses Plus Student 29,439 Points

You have two options when it comes to chatting, point-to-point and that will be like SMS-ing between two persons or implement chat rooms where more than 2 people can "join" and send messages.

Option 1 - Point-to-Point chat

The point-to-point method is rather simple to implement. Have the users sign-up inside your app, save their info using Parse and have them friend each other. You can get this part from the Ribbit app. Once a user sends a chat message to another user, save this message in Parse with a target field value of the targeted user's id - again a simple operation to do.

The next part is the "heart" of the chat... have you app check every 3 / 5 seconds with Parse for new messages towards the user using the app right now using his userID. This process is called heartbeat and you can decide on the timing between beats. Any messages having the current user's ID as a target get displayed under the respective sender's avatar...

Option 2 - Chatrooms

The chatroom method is a bit similar to the p-t-p but it involves creating an unique ID for a chatroom and having the app send messages towards that ID ( instead of a user's ID like in p-t-p ). Also this chatroom should have another field containing the user IDs that register with it. For example 3 or 4 users might join the same chatroom, their IDs are registered with this certain chatroom ID.

The heartbeat process now checks to see if there are any messages for its unique ID, if any messages it delivers them to the user IDs that have registered with the chatroom. Once a user leaves the chatroom, his ID is disassociated with the chatroom's ID and he no longer receives new messages in the room.

Hope this helps. Cheers!

Do you know any article or sample code for the second option please

Robert Bojor
Robert Bojor
Courses Plus Student 29,439 Points

No article that I know of, the two options I've gave you above are from my personal experience with online chatting and implementing these ideas on the web. The principles are the same only the programming language changes.

I can attempt coding the chatting platform, mind you it'll take me a while since I'd do it in my spare time, and also it will be public for anyone to use, if you don't mind...

No you don't have to code it but thanks for your help