player:receivedTurnEventForMatch:didBecomeActive: inconsistently/rarely fires
Asked Answered
C

2

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?

Cholera answered 12/12, 2013 at 20:24 Comment(1)
Did you find anything better than the workaround?Imposture
C
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.

Coke answered 25/12, 2013 at 18:6 Comment(5)
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.Cholera
It was my investigation. Also read about that on stackoverflow: #15958076Coke
Also it was described regarding receiving invitations: developer.apple.com/library/ios/documentation/…Coke
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.Cholera
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.Coke
C
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.

Cholera answered 25/12, 2013 at 18:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.