Reputation: 7104
I am working on a multiplayer game through game center and I am having one problem. When I try to invite one of my friends I get failed status. I have tried with simulator and iphone and with two iphones and always the same problem.
I have searched a solution for my problem and found out that there are many developers with this problem. I am using iOS 6 and app is still in production so it is in sandbox.
I am using same code like is on Ray Wenderlich tutorial - CatRace (there have too people writen about this problem but nobody has post a solution.
Does anybody know how to solve that problem?
Upvotes: 3
Views: 6367
Reputation: 559
You have to send a GK event to signify the player (you) ended their turn before GameCenter will send a push notification invite to the players you invited.
So the first round of events for each player should send a matchData array of something like [“Player1” : “Joined”]
That will force GameCenter to send an invite to each player.
Then once you confirm that each player has sent a “Joined” GK event, you start the game.
https://developer.apple.com/documentation/gamekit/gkturnbasedmatch/1520765-endturn
func endTurn(withNextParticipants nextParticipants: [GKTurnBasedParticipant],
turnTimeout timeout: TimeInterval,
match matchData: Data,
completionHandler: ((Error?) -> Void)? = nil)
The nextParticipants are the invited players and the matchData is an NSArray like [“Joined”] using NSKeyArchiver. Once you invoke this function, GameCenter will send a Push Notification to invite the player.
Upvotes: 0
Reputation: 1918
Please Check this:
1> You set inviteHandler just after the local player has authenticated.
2> The player you're trying to invite did allow game invites in their account settings. In case you had two test accounts, you could forget you disallowed it for both of them. In such case the push notification for invite won't even be sent to the other player.
3> Do not use same game center account for testing.
Upvotes: 7