Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get notifications for GameKit Turn-Based matches?

I'm working on a turn based iOS game using the new turn-based iOS5 API.

One of the delegate protocols you need to implement for this is GKTurnBasedEventHandlerDelegate. One of the methods to implement is handleTurnEventForMatch. This is from the Apple docs on this method:

handleTurnEventForMatch

Sent to the delegate when it is the local player’s turn to act in a turn-based match.

- (void)handleTurnEventForMatch:(GKTurnBasedMatch *)match

Parameters

match - A match object containing the current state of the match.

Discussion

When your delegate receives this message, the player has accepted a push notification for a match already in progress. Your game should end whatever task it was performing and switch to the match information provided by the match object.

Most of my game is working. I'm getting notifications of moves received via the above method. I'm also seeing badges on the app icons being updated successfully.

However, I am not getting any other system notifications when turn events come in; nothing shows up in the notification center, etc. Do I need to do something outside of GameKit to enable this? Do I need to manually send a local notification when I get handleTurnEventForMatch? The docs seem to imply not since it says above "When your delegate receives this message, the player has accepted a push notification for a match already in progress."

So this seems to imply that the player has clicked on a push notification to get this method called (but of course they never appear, so I have not!)

What do I need to do to enable push notifications in my app for turn-based events? Do I need to actually send a local notification when I receive the above method (this would seem to contradict the intent, given the verbiage of the above doc).

like image 446
John Stewart Avatar asked Oct 28 '11 21:10

John Stewart


2 Answers

I just finished fighting my way through this, and after a week or so of banging my head against the desk I discovered these important things:

(1) The simulator does not receive these turn notifications. Once I made this work, it works fine between two devices. A simulator playing versus a device will send events, but not receive them. So if you are trying to use one device and the simulator to test this, good luck. Use two devices.

(2) Make sure that you have "Game Center Enabled for this Version" turned on in iTunes connect, and make sure that the CFBundleVersion in your app matches this version. As soon as I did this, everything started working.

I assume you have already done: [GKTurnBasedEventHandler sharedTurnBasedEventHandler].delegate = YOUR_DELEGATE_CLASS;

like image 94
Tom Schulz Avatar answered Oct 20 '22 18:10

Tom Schulz


Tom Schulz said true. But one thing! : you can get notifications with your device but not with simulator . To do this always reset your simulator content and settings before build and run . And on the simulator you can use load matches method to receive something for tests. Hope it helps

like image 39
Salih Ozdemir Avatar answered Oct 20 '22 18:10

Salih Ozdemir