How to solve inviting friend over game center?
Asked Answered
E

2

3

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?

Eberhart answered 13/1, 2013 at 20:52 Comment(2)
you can't test invitation code in simulator .you have to test it on twodevice .Please check this link #10971038 this will solve your problem.Ayotte
@mitu - I have tested on two iPhones.Eberhart
A
7

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.

Ayotte answered 18/1, 2013 at 12:51 Comment(0)
A
0

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.

Agrology answered 25/3, 2021 at 1:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.