I have an in-application messaging for one of my apps. But it’s not very efficient. Checking and updating messages causes lags in the GUI.
I need to be able to allow sending and receiving of text and images. I have some proprietary information that is shared too, but I can figure out how to encode that in a message.
I am more than positive someone has found a creative way to do this already.
Suggestions are appreciated.
Hey Chris. I have a unified inbox in my app with both email and SMS (text) messages in it — not in-app messaging but I guess similar — and I don’t have UI lag. Just in case it helps, here’s how I do it:
- The Messages screen, which is a tab in my UI that looks like the Messages app on your phone, displays cached data from my app’s SQLite database so it always loads and presents data straight away.
- When it is first opened, or when the user pulls-to-refresh, I call an endpoint to get the first page of messages (our API returns 50 messages at a time based on the page number out of potentially hundreds of pages/thousands of messages).
- The messages JSON data is parsed in a thread so it doesn’t block the UI and is saved to my app’s database so the UI can get the latest messages from the database.
- As the user scrolls down through the table, my app keeps track of which page it has loaded up to and calls the API to retrieve additional pages as the last row approaches if/when required. I display a progress spinner on the last row if the next page of messages hasn’t been fetched by the time the user gets there. Since I first wrote this, @Antonio_Rinaldi has released a much more elegant prefetch interface for his excellent iOSMobileTableExtended, which I’m now using in a different screen/table, and which takes a lot of the hard work out of this code. It’s well worth checking out.
- In terms of updating data, our API uses Server Sent Events (SSE) to notify my app of new messages arriving or messages being changed or deleted and so I act on those SSE notifications, fetch the changes and update my local database in a thread before refreshing that message in the table if I have it loaded.
I hope this helps!
This is very helpful.
Here is a bit more of my situation.
I’m using a Xojo Cloud server which hosts the database.
There will be an active web interface for reporting (etc)
Right now I’m using a URLSocket to connect authenticate, and to synchronize data. Using the URL socket has a benefit and drawback. The benefit in this case is that it uses HTTPS and I’ll encounter a lot fewer firewall issues. The downsize (unless I’m missing something) is that I have to poll for new data and that causes a lot more traffic than I want to invoke.
I’ve done a lot of client-server work for internal networks where I don’t have to worry about any firewalls as it’s always a controlled environment.
Is it reasonable that I implement a server socket on a Xojo cloud server with a custom port number and use the cloud server this way?