开发者

iOS Development: When receiving a Game Center invite, how do I obtain the GKMatch object?

I'm building an iPhone game that uses Game Center and I'm having a hard time understanding how to start a match game that was started by receiving an invitation to play from a friend. The docs say this...

The acceptedInvite parameter is non-nil when the application receives an invitation directly from another player. In this situation, the other player’s application has already created the match request, so this copy of your application does not need to create one.

According to this, I don't need to create a match request since the player who did the inviting already created one. If so, how do I obtain the GKMatch object needed to send/receive data to/from the other player? The only way that I know to get the GKMatch object is to create a match request and call the findMatchForRequest method, which the docs are saying I shouldn't do.

The only code example they have for this invo开发者_StackOverflow中文版lves creating and using the GKMatchmakerViewController, which I can't use since I'm creating my own custom views.

Thanks so much for your wisdom!


I received a response from one of the Apple engineers on this, here's what he said...

You can do auto-matching with custom views, but there is no way to use invites without using GKMatchmakerViewController. So you should follow the code sample.

I guess there's just going to have to be a radical break in the consistency of my UI.


I have a fix to the game center invite problem. So follow these steps:-
1- check that your push notifications are on in settings and friend invites are on in your game center account setting.
2-now install the latest version of fruit ninja game
3-open game center and sign in, then put it in background.
4-open fruit ninja directly goto new game=>multiplayer=>gamecenter
5-now you will see two options (invite friend & play now at the top right corner)
6-hit the play now button, so the game center will find the uninvited game for you.
7-when the game starts and you are able to see your uninvited friend's name at the top right corner. After the game finishes, go directly to game center in the background and in your games section and go into fruit ninja in game list. Here you will see the recently played option, Touch it. Here you will see at the top of the list a player name (who you played with) touch the name and send him friend request immediately.
8-if he accepts request goto friends=>(your recently added friend)=>gameplayed together(fruit ninja)=>hit play(at upper right)
9-now the game will open up and you will see the GC page. Hit the invite button and choose the recently added friend, and then send, waiting for him and ready to play.

Now your gc id have verified and you can invite any of your friends and can play any game(which supports the invite feature)


Despite what the Apple engineer said, how about try something like this to invite without using a custom view:

[[GKLocalPlayer localPlayer] loadFriendsWithCompletionHandler:^(NSArray *friends, NSError *error) {



[GKPlayer loadPlayersForIdentifiers:friends withCompletionHandler:^(NSArray *players, NSError *error) {
    for (GKPlayer *player in players) {
        NSLog(@"%@",player.alias); //here I'm just logging the aliases but the array players can be used in any way
    }
}];

} ];

Now if a user selects players from this list on a custom view, GKMatchRequest has a property called playersToInvite and we can set these players to that property. And create a match programmatically using this request.

This looks very possible but I haven't tried it to be honest

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜