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.
gamekit game-center
leontx
source share