Throughout the testing of my game, I have noticed multiple unexpected message events provided by Game Center which required me to add special code handling to overcome. I confirmed all of these issues occur more often then I would have thought.
Has anyone else experienced these issues as well?
Issues
1) Game Center sends CONNECTED for all players then immediately sends DISCONNECT for one player before the match even had a chance to start
Game Center sends a "match(didChange state)" CONNECTED indication for each non-GKLocalPlayer in the match (as expected) and eventually indicates the expectedPlayerCount is 0 so match start processing can begin (as expected), which involves loading all other player information via GKPlayer.loadPlayers(forIdentifiers: ) method. However, Game Center will then sometimes immediately send a "match(didChange state)" DISCONNECT, indicating one of the other players has disconnected from the match, even though that player never quit/disconnected from the match themselves. Also, no other player in the match receives this same DISCONNECT event either. The player who was disconnected from Game Center still maintains two-way network connections to other players and a one-way network connection to the player who did receive the disconnect event, so the player is clearly not totally disconnected.
This quick DISCONNECT event arrives before "match start" processing has even completed (ie: before GKPlayer.loadPlayers completion handler is called). This has been experienced in 3 and 4 player matches
2) Game Center sends a separate CONNECTED state change event for both players and both CONNECTED events indicate expectedPlayerCount = 0
In a three player game, the GKLocalPlayer, who requested the match to be created, will receive a separate "match(didChange state)" CONNECTED indication for each of the other two players in the match (as expected), however, both individual CONNECTED events will have expectedPlayerCount = 0. I was under the impression only the last CONNECTED event would indicate expectedPlayerCount = 0 (ie: all players are ready), but that is no the case. This has been experienced in 3 player matches.
3) Game Center sends two DISCONNECT state changes for the same player back to back
When a player quits from my game, then I ensure the match is disconnected by calling "myMatch.disconnect( )". When this occurs, it is expected that all other players still in the match will receive one DISCONNECT state change event from Game Center, indicating one of the players have quit/disconnected from the game. However, I see Game Center sometimes sends two "match(didChange state)" DISCONNECT events one after the next. This has been experienced in 3 and 4 player matches
4) Messages never arrive at the intended player destination
Messages sent from one player, using the following ".reliable" protocol, results in the message never arriving at the intended player. This is very annoying when the message which never arrives is the initial "game init data" message which includes all of the information required to sync up the game between all players before it starts. This has been experienced in 3 and 4 player matches.
myMatch?.send(data, to: playerArray, dataMode: .reliable)