6

I am currently testing my Game Center Aware App using the Game Center Sandbox, with one instance running on the iOS simulator and the other on an Retina iPad Mini. I have a view controller which needs to receive turn events, so I implement the method

player:receivedTurnEventForMatch:didBecomeActive:

in the GKLocalPlayerListener protocol, which my UIViewController subclass adopts, and then register for events with this line

[[GKLocalPlayer localPlayer] registerListener: self];

in the init method of the view controller. However, despite the Game Center App saying that the two instances of the game have connected, this method is rarely called on the iPad, and I dont't think I've ever seen the simulator instance calling it. However, going to the Game Center App shows that both instances are updated, showing that both instances are capable of receiving the event. What could be causing this?

Ben Pious
  • 4,765
  • 2
  • 22
  • 34

2 Answers2

2

I had the same problem on iOS 7/Xcode 5/iPhone 5. To fix that issue you need just add "Game Center" entitlement to your App ID. You can do that by navigating to project's "Capabilities" tab in Xcode.

Please note that player:receivedTurnEventForMatch:didBecomeActive: will be fired on devices only.

Serge
  • 2,031
  • 3
  • 33
  • 56
  • Thanks, but that wasn't the problem -- I had the game center entitlement added before I asked. I am curious to know where you read that that selector is only fired on devices though... I didn't see it in the docs, though it definitely seems to be true. – Ben Pious Dec 25 '13 at 18:47
  • It was my investigation. Also read about that on stackoverflow: http://stackoverflow.com/questions/15957576/gkturnbasedmatch-receive-data – Serge Dec 26 '13 at 11:10
  • Also it was described regarding receiving invitations: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/TestingYourGameCenter-AwareGame/TestingYourGameCenter-AwareGame.html – Serge Dec 26 '13 at 11:17
  • I've seen that page, it *doesn't* actually say you won't receive turn events on devices, merely that they can't respond to invitations. – Ben Pious Dec 26 '13 at 16:17
  • Correct. But as Apple says: "GKInviteEventListener uses the GKLocalPlayerListener mechanism on GKLocalPlayer to listen to the two kinds of invite events that a game must respond to". The assumption is that it won't work on simulator as well. I guess it's logically understandable point. – Serge Dec 27 '13 at 15:06
1

The workaround I found for this issue on the simulator is to call the

loadMatchDataWithCompletionHandler:

method when a refresh button is pushed in the UI, which causes match data to be loaded in the simulator.

Ben Pious
  • 4,765
  • 2
  • 22
  • 34