问题描述:

I have a chat feature in my app using JSQMessagesViewController (https://github.com/jessesquires/JSQMessagesViewController).

It makes an API call to my server every 5 seconds to get all the chat messages between two users to populate the chat view with those messages. It was suggested I turn that into a socket connection because making an API call every 5 seconds will be hard on the battery and a waste of API calls.

How do I turn my chat feature into a socket connection with my server?

Are there any libraries in Objective-C that will help me accomplish this? And also, I'm pretty sure that I'll have to set this up on the back end too, so are there any resources as to how to set this up on a PHP Laravel backend?

网友答案:

You should be able to accomplish this using a couple mature libraries on both the iOS frontend and the PHP backend.

iOS: SocketRocket

https://github.com/square/SocketRocket

PHP:: Ratchet

http://socketo.me

They both support RFC 6455 so should integrate pretty easily.

Since you are using PHP, I'm going to take a stab and guess you are using Apache? If so, here is some more information on setting up websockets to work with Apache which can have issues with connection management: Setting up a websocket on Apache?

相关阅读:
Top