[GKMatchmaker sharedMatchmaker].inviteHandler is deprecated in iOS 7, yet the GameKit guides still say to set it up that way. Does anyone know what we're supposed to be using for iOS 7 real time game invites? There are new classes / methods for several listener classes, but none address this specifically that I have seen.

'inviteHandler' is deprecated: first deprecated in iOS 7.0
有帮助吗?

解决方案 2

It looks like the intended replacement is the GKInviteEventListener protocol. You can see a reference to it in GKLocalPlayer.h; the GKLocalPlayerListener protocol extends it.

However, there's limited documentation on this protocol (you can search for it in the documentation window of Xcode 5, but I don't see it on the web).

Given the lack of documentation, it's probably safest to continue using the deprecated method for now. You'll need to continue using it anyway for iOS6.

其他提示

So I was starting to get really frustrated with this (almost magically, the deprecation warnings started showing up in my console yesterday). Apple doesn't seem to spell out how an object can be set as the thing that implements the new GKLocalPlayerListener protocol.

Here's how I did it. Just after authenticating my local player, I registered the object that implements the GKLocalPlayerListener protocol (in this case self) as the Listener. I tested how my app responds to the same Game Center events, and it has responded accordingly. I believe this is the proper way to do it, although I am still questioning which place is the best for registering the listener. I believe it makes sense to do it after the player is authenticated, but it may be more subtle than that.

NSLog(@"Authenticating local user...");
__weak GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];

localPlayer.authenticateHandler =
^(UIViewController *viewController,
  NSError *error) {

    [self setLastError:error];

    if (localPlayer.isAuthenticated) {

        [localPlayer registerListener:self];

    } else if(viewController) {

        [self presentViewController:viewController];
    } else {


    }
};

You also want to avoid registering the listener more than once. It's kinda like registering an observer for a local notification. If you do it more than once, your listener methods end up getting called more than once.

I believe the method that replaces:

-(void)handleInviteFromGameCenter:(NSArray *)playersToInvite;

Is the following:

-(void)player:(GKPlayer *)player didRequestMatchWithPlayers:(NSArray *)playerIDsToInvite;

From reading the documentation, there is mention of creating a GKMatchMakerViewController (or something similar that's a little more bespoke) when this is called. I know that's what I was doing in previous versions of my app, so it can't be that far off. The structure of the method is also quite similar.

More testing will confirm if this is indeed the right way of approaching the new protocol, but so far it seems to be correct. I'm gonna continue with this until directed otherwise.

If you're running a GKTurnBasedMatch, it's a special case. For a GKTurnBasedMatch, invites are considered turn events, and are recieved by the registered GKLocalPlayerListener in the function:

player(_ player: GKPlayer, receivedTurnEventFor match: GKTurnBasedMatch, didBecomeActive: Bool)

I'm trying to run a GKTurnBasedMatch and it took me days to find this information, so I hope I've helped someone else out by posting this here.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top