3
votes

We have an game that creates a player lobby using sockets. When the player creates a lobby, a game is created on our server. Unfortunately if the user switches our app away with the Apple button, another user may join the game and the game will start with just one player active. So we want to send a message to our server via a socket when the app transitions to the background to close the lobby, stopping others joining.

But we can't. The sockets get frozen on entering background mode. Even if we keep the app alive a while using beginBackgroundTaskWithExpirationHandler, no socket activity works.

VOIP is not an option, as the title is not VOIP related and will get bounced immediately from Apple submission.

Any one got any non-VOIP related ideas?

Many thanks,

Steve.

1

1 Answers

2
votes

I think what you want to do is to let the server know that this user is off-line when touching the Apple Home button.

I am using GCDAsyncSocket, but other ways may be similar.
What I'm doing is

  1. Add observer on UIApplicationDidEnterBackgroundNotification.

  2. When application enter background then call socket disconnect. The server will know that you are off-line.

I know this is a little late for your answer, but could be helpful for others.