phpswiftsocketswebsocketstarscream

Keeping socket open in Swift for chat application


I have a working chat server in Php/Ratchet. I am using Starscream as my client in Swift. I successfully created a chat between users however this only works when my application is open because this is when the socket is open. How do I make my app receive messages even if my app isn't on. So basically is there a way to keep sockets open. I read somewhere that it is forbidden by Apple.


Solution

  • Sounds like you are sending messages from your client to your phone. You need to send messages to a server and the server sends them to your phone.

    The server, if unable to successfully send a message to your phone, should store the message and should send the stored messages to the phone when the phone is available.

    There are message queuing systems for things like this. See, for example, RabbitMQ. There are loads of others too that may work better with your tech stack. Do some research.

    Here the client talks to the server, the server hooks up with RabbitMQ or whatever you choose to use, RabbitMQ keeps a track of queued messages and when the phone comes online, RabbitMQ sends the queued messages to the server and the server sends them to the phone.

    PS Google "message queue PHP".