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

后端 未结 3 1568
野性不改
野性不改 2021-02-06 15:54

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

相关标签:
3条回答
  • 2021-02-06 16:39

    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)

    0 讨论(0)
  • 2021-02-06 16:42

    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.

    0 讨论(0)
  • 2021-02-06 16:47

    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 讨论(0)
提交回复
热议问题