Rohit Goyal
Rohit Goyal

Reputation: 1539

How to receive turnbased matchData while entering game through gamecenter app?

I am using GKTurnbasedMatchMakerViewController to start a new turnbased game or check the existing ones and that is working perfectly fine. However I am stuck at this case scenario: Suppose pleayer opens the gamecenter app in his mobile and sees an existing turnbased match there. He clicks on the match and clicks the the button view turn/play turn(depending upon whose turn it is currently) which brings him into my app. Now what I want is the match data like we get from GKTurnbasedMatchMakerViewController on delegate didFindMatch so that I can show him the appropriate UI.

Currently after reading a lot I found GKLocalPlayerListner might be what I am looking for. So here is what I did.

Added GKLocalPlayerListner in my class extensions.

registred listener for local player while authenticating the user.

func authenticateLocalUser() {

        println("Authenticating local user...")
        if GKLocalPlayer.localPlayer().authenticated == false {
            GKLocalPlayer.localPlayer().authenticateHandler = { (view, error) in
                if error == nil {
                    println("authentication")
                    self.authenticated = true
                    GKLocalPlayer.localPlayer().registerListener(self)
                } else {
                    println("\(error.localizedDescription)")
                }
            }
        } else {
            println("Already authenticated")
//            GKLocalPlayer.localPlayer().registerListener(self)
        }
    }

Added GKLocalPlayerListener delegate methods in my class.

// MARK: GKLocalPlayerListener

func player(player: GKPlayer!, didAcceptInvite inviteToAccept: GKInvite!) {
    println("turnbased: didAcceptInvite")
    let mmvc = GKMatchmakerViewController(invite: inviteToAccept)
    mmvc.matchmakerDelegate = self
    presentingViewController.presentViewController(mmvc, animated: true, completion: nil)
}

func player(player: GKPlayer!, didRequestMatchWithOtherPlayers playersToInvite: [AnyObject]!) {
    println("turnbased: didRequestMatchWithOtherPlayers")
}
func player(player: GKPlayer!, receivedTurnEventForMatch match: GKTurnBasedMatch!, didBecomeActive: Bool) {
    println("turnbased: received turnbased match with didBecomeActive = \(didBecomeActive) and match = \(match.description)")
}

func player(player: GKPlayer!, didReceiveChallenge challenge: GKChallenge!) {
    println("turnbased: Challenge received")
}

But I am not able to get any of these while entering the game from gamecenter app.

So first of all does GKLocalPlayerListener even do what I am trying to achieve? If not is it even possible in iOS to achieve what I want? Please help me through this.

Upvotes: 1

Views: 201

Answers (2)

sdc
sdc

Reputation: 3031

Apple has chosen to

remove this feature

Proof from an Apple bug report that I submitted.

Apple bug report

Upvotes: 0

Thunk
Thunk

Reputation: 4177

I have not found anyway to do this as of IOS8.4. ReceivedTurnEvent only fires when an event is generated. Launching the app from gameCenter does not appear to generate an event. I've looked at parameters passing in via arguments and set in environment variables and have yet to find any hit as to which match was selected in the gameCenter App.

Related: Handle Selected Turns/Games in iOS Game Center App in Game Center Enabled App

Upvotes: 1

Related Questions