11 Replies
      Latest reply on Dec 27, 2019 11:04 AM by uncletr
      uncletr Level 1 Level 1 (0 points)

        When a user is not currently in the game application, I understand Game Center with push an Invite notification to the user's device asking them if they want to play the game.  If they accept the invitation then Game Center will open the application automatically on the user's device.

         

        How can the game application know it was started as a result of an accepted invitation?   If this can be determined then I can place the user into the game right away and bypass any option screens, displays menus, etc. which are no longer required.

        • Re: How can the application know it was started as a result of a Game Center Invite request?
          KMT Level 9 Level 9 (15,455 points)

          I think this is all predicated on user authentication?

           

          See the docs on 'Enable Other Game Center Code Immediately After a Player Is Successfully Authenticated'

           

          Common Tasks When Working with Players

          • Re: How can the application know it was started as a result of a Game Center Invite request?
            PBK Level 7 Level 7 (3,525 points)

            My recollection is that one of these is caled:

             

            - (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match{

            https://developer.apple.com/documentation/gamekit/gkmatchmakerviewcontrollerdelegate/1492416-matchmakerviewcontroller?language=objc

             

            or

             

            - (void)player:(GKPlayer *)player didAcceptInvite:(GKInvite *)invite{

            https://developer.apple.com/documentation/gamekit/gkinviteeventlistener/1520672-player?language=objc

            • Re: How can the application know it was started as a result of a Game Center Invite request?
              uncletr Level 1 Level 1 (0 points)

              ok thanks.   I guess I just need to keep an indicator as to whether I created the match request or not.  This way, when the didFindMatch or didAcceptInvite method is called in my application and also in the invited-player's application then I can tell who started the game.  If I did not create the match then I must have been invited.  Does this make sense?

                • Re: How can the application know it was started as a result of a Game Center Invite request?
                  PBK Level 7 Level 7 (3,525 points)

                  In my code didAcceptInvite launches a GKMatchmakerViewController which then results in a call to didFindMatch.

                   

                  In the unlikely event that the device receiving didAcceptInvite is already trying to invite someone then didAcceptInvite first dismisses the GKMatchmakerViewController before launching a new GKMatchmakerViewController

                   

                  I then offer both players a choice as to who will start the game (with their pre-existing board setup).  Collisions can be handled by transmitting a device ID and having the higher device ID win any collision.

                    • Re: How can the application know it was started as a result of a Game Center Invite request?
                      uncletr Level 1 Level 1 (0 points)

                      Thanks for pointing out the clash which can occur if two players are setting up a match at the same time.  Two players might be requesting each other to join into a new match request at the same time OR the invited player might be setting up a match which does not include the player who is sending the invite request.   I will need to think about these two scenarios after I get a basic match set up and working orf course.

                       

                      I have never been invited into a game center game before so cannot understand what an "invited player" actually sees on their screen.  I assume the invited player would just have to accept/decline a "Do you want to play?" question from Game Center.  If they accept the game then the folwing would occur .... but perhaps you can confirm?

                        

                      1) The didAcceptInvite method would be called on the device of the invited player only

                       

                           func player(_ player: GKPlayer, didAccept invite: GKInvite)

                       

                      2) inside the didAcceptInvite method there would be a call to the following method so the invited player can create the "match" (based on the data in the invitation) on their device:

                       

                           func match(for invite: GKInvite, completionHandler: ((GKMatch?, Error?) -> Void)? = nil)

                       

                      3) The following method would be called on the device of the player who is sent the invite so they know the invited player accepted (ie: connected) the match invitation:

                       

                          func match(_ match: GKMatch, player: GKPlayer, didChange state: GKPlayerConnectionState)

                       

                      Question:

                      Why do you need to present a "new GKMatchmakerViewController" to the invited player in the didAcceptInvite method?   We do not want the invited player to start selecting friends and setting up a match themselves so I am confused what the view controller provides to the invited player

                        • Re: How can the application know it was started as a result of a Game Center Invite request?
                          PBK Level 7 Level 7 (3,525 points)

                          >  I have never been invited into a game center game before so cannot understand what an "invited player" actually sees on their screen.

                           

                          Again.....download and try (edit - ) Go Game Connect - invite a friend, have them invite you, accept their invitation, decline their invitation.  The app is free for the first few games.

                           

                          1) The didAcceptInvite method would be called on the device of the invited player only

                           

                          Yes

                           

                          2) inside the didAcceptInvite method there would be a call to the following method so the invited player can create the "match" (based on the data in the invitation) on their device:

                           

                          For some reason (I don't recall why) my didAcceptInvite:invite  presents this:

                            GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithInvite:invite];
                            

                           

                          then both the inviter and the invitee can respond to calls to

                           

                          (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match

                           

                          3) The following method would be called on the device of the player who is sent the invite so they know the invited player accepted (ie: connected) the match invitation:

                           

                              func match(_ match: GKMatch, player: GKPlayer, didChange state: GKPlayerConnectionState)

                           

                          My code uses this method only to enable/disable a reconnect button.  It reklys on didFindMatch to start the game on both devices.

                           

                          Why do you need to present a "new GKMatchmakerViewController" to the invited player in the didAcceptInvite method?   We do not want the invited player to start selecting friends and setting up a match themselves so I am confused what the view controller provides to the invited player

                           

                          Unfortunately I do not have access to (edit - )Go Game Connect on two devices right now so I can't answer this question.  I would be pleased to invite you if you give me your Game Center ID.

                          • Re: How can the application know it was started as a result of a Game Center Invite request?
                            PBK Level 7 Level 7 (3,525 points)

                            You asked:

                             

                            Why do you need to present a "new GKMatchmakerViewController" to the invited player in the didAcceptInvitemethod?   We do not want the invited player to start selecting friends and setting up a match themselves so I am confused what the view controller provides to the invited player

                             

                            I have been struggling with this question.  I think the answer is that the didAcceptInvite method is called at the moment the invited player accepts the invite.  At that same moment a match has not yet started and it is unclear whether a match will start - all we have is an invite and an intent to accept that is not yet been transmitted back to Game Center.  The invited player sends a signal back to the inviter saying that they accept.  If things work out correctly then Game Center will start a match and call didFindMatch: .  You need to receive that didFindMatch: and that's why you set up the viewCotroller.  [ Perhaps you only need to set up the delegate (not present the viewController) to receive the didFindMatch:  ]