Apple introduced "Exchanges" for turn-based multiplayer games in iOS 7. One of the possible applications that they talked about were chat features. Therefore, I tried to implement the chat function for my game using exchanges, but exchanges really are not suitable for this. Since Apple specifically mentioned this, I thought my approach was simply wrong.
My approach is to send an exchange request for each chat message with the message body embedded in the request. The other player receives the request, retrieves the message and saves it locally, and then responds to the exchange to complete it. Finally, the player who is about to send the turn must first check to see if there are completed exchanges and allow them. Some of the issues I am facing are:
- The game center sends notifications when responding to an exchange request. So, if player 1 sends a chat message to player 2, then player 1 will receive a notification when player 2 receives the message. There is no seemingly way to turn off notifications for response events, so if the application is closed or in the background player 1 will receive a Game Center banner.
- To allow the exchange, I need to call
saveMergedMatchData:withResolvedExchanges:completionHandler:who sends the updated game data to the Game Center. But in this case, these games remain unchanged, so I have to accidentally download additional data, which can be expensive when a player has a poor Internet connection. - Sending a queue to Game Center before resolving all open exchanges results in an error. Therefore, all exchanges must be resolved first. The GKTurnBasedMatch object contains an βexchangeβ array containing all unauthorized exchanges, but this data may be outdated if another player has already answered one of our exchanges. So I need to load matchData again for the current match to check for unauthorized exchanges before I can make a move.
Is there a better way to implement a chat feature using exchanges?