Invite a Game Center friend to software matching

Does GameKit allow you to invite an individual Game Center friend into compliance programmatically, that is, without a GC ViewController? The following documentation, handleInviteFromGameCenter, seems to imply that you can populate GKMatchRequest.playersToInvite and use it with [GKTurnBasedMatch findMatchForRequest]:

When your delegate receives this message, your application should create a new GKMatchRequest object and set the playersToInvite parameter to match the request for the playersToInvite property. Then your application can either call the GKTurnBasedMatch class method findMatchForRequest: withCompletionHandler: find a match programmatically , or it can use the query to create a new GKTurnBasedMatchmakerViewController to display the user interface with the player.

But I find that when findMatchForRequest calls my completion block with a filled match, the GameCenter ID that I passed to it is not set as the second player. Instead, it is empty, and the status is "consistent." And so when I call endTurnWithNextParticipant, it succeeds, but the invitation was not received on my second device. This illustrates what I am doing:

GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease]; request.minPlayers = 2; request.maxPlayers = 2; request.playersToInvite = [NSArray arrayWithObjects: otherPlayerGCID,nil ]; [GKTurnBasedMatch findMatchForRequest:request withCompletionHandler:^(GKTurnBasedMatch *match, NSError *error) { if (error) NSLog(@"returned from fimdmatch but with error"); else if (match != nil) { NSLog(@"match returned success and match populated"); NSArray* otherPlayers = [match participants]; if (otherPlayers.count>1) { NSData* placeholder = [@"no data" dataUsingEncoding:NSUTF8StringEncoding]; [match endTurnWithNextParticipant:[otherPlayers objectAtIndex:1] matchData:placeholder completionHandler:^(NSError *error) { if (error) NSLog(@"returned from END TURN but with error"); else NSLog(@"returned from END TURN successfully"); }]; } } else System::log("match returned success but match NOT populated"); }]; 

And as a person who seems to have a similar issue here Game Center inviting friends progamically if I insert a call to the view controller, in my case GKTurnBasedMatchmakerViewController, everything seems to work.

Thanks.

UPDATED: I saw a step-by-step GC in an Apple Developer presentation, mentioning something like: "If you want to invite a friend to GC, we ask you to go through the GC view controller.

Any insight appreciated. Thanks again.

+8
gamekit game-center
source share
1 answer

I wanted to share what I learned about this: with iOS 5 there is no way to invite a friend of the game center to play the game without going through the predefined GKTurnBasedMatchmakerViewController stream, which is optimized to start the match in real time, directing the user through three different screens.

After I highly recommended apple dev support, I sent a feature request to be able to call a simple one page controller that would allow the user to send an invitation / "recommend game" message through the game center.

UPDATE FOR iOS 6: We are pleased to announce that it looks like it was considered in iOS 6. My original software (non-user) example above now works as expected.

+7
source share

All Articles