1

我在 Game Kit 程序化匹配上玩得很开心,并且只能假设尽管阅读了所有教程,但我可以亲自动手......我在某处弄错了流程。

登录到沙盒工作正常,该应用程序正在分发一个应用程序 ID 特定的配置文件,该配置文件启用了游戏中心。一切似乎都很好,只是它永远不会找到另一个“附近”的玩家。

下面的代码是我的身份验证处理程序,它被正确调用,但正如我所说,尽管它记录了“正在为附近的玩家启动浏览器”,但从未报告过,同一 wifi 网络上的蓝牙等等等。我对我是什么感到非常困惑做错了。

-(void) authenticationHandler{

if ([_currentScene conformsToProtocol:@protocol(BOMScene)]){

    MyScene<BOMScene> *theScene = (MyScene<BOMScene> *) _currentScene;
    //Make sure the current scene gets the message that they are now authenticated
    if ([GKLocalPlayer localPlayer].isAuthenticated){
        [theScene localPlayerAuthenticated];
    } else {
        [theScene localPlayerDeauthenticated];
    }
}

NSLog(@"Game Center Status Change: %@", _localPlayer.authenticated ? @"Available" : @"Not Available");

if (_localPlayer.authenticated){
    if (!_matchMaker){
        _matchMaker= [GKMatchmaker sharedMatchmaker];
        NSLog(@"Starting to browser for nearby players");
        [_matchMaker startBrowsingForNearbyPlayersWithReachableHandler:^(NSString *playerID, BOOL reachable) {
            NSLog(@"Nearby player %@ is %@",playerID, reachable ? @"available" : @"no longer available");
            if (reachable){
                [_nearbyPlayers addObject:playerID];
            } else {
                [_nearbyPlayers removeObject:playerID];
            }
        }];
    }

} else {
    _matchRequest = nil;
    [_matchMaker stopBrowsingForNearbyPlayers];
    [_nearbyPlayers removeAllObjects];
    _matchMaker = nil;
}        
4

1 回答 1

0

You need to install an invitation handler.
Please see my answer here for a full breakdown:

Some startBrowsingForNearbyPlayersWithReachableHandler questions

于 2014-10-07T04:38:12.733 回答