在游戏中心找不到玩家.我测试我的游戏是不是错了



我让游戏在Xcode模拟器和iPhone上运行。当我点击搜索时,它们都被放入单独的游戏中,而不是一个玩家加入现有的游戏。这是一款回合制游戏,玩家可以在游戏中心自动匹配时进行第一回合。我正在使用两个单独的游戏中心帐户,并启用了沙盒设置。知道我可能做错了什么吗?对于那些开发了 Game Center 支持游戏的人,您是如何测试它的?感谢您的帮助!

一些代码:

- (void)findMatchWithMinPlayers:(int)minPlayers maxPlayers:(int)maxPlayers // view controller calls to find match - nothing if GC unavaiable
             viewController:(UIViewController *)viewController {

if (!_enableGameCenter) return;

_matchStarted = NO; // Match not started yet
self.currentMatch = nil;
[viewController dismissViewControllerAnimated:NO completion:nil];
GKMatchRequest *request = [[GKMatchRequest alloc] init]; // Set number of players
request.minPlayers = minPlayers;
request.maxPlayers = maxPlayers;
GKTurnBasedMatchmakerViewController *mmvc = // new instance of the GKMatchmakerViewController with the given request, sets its delegate to the GameKitHelper object, and uses the passed-in view controller to show it on the screen. Shows the user to search for a random player and start a game.
[[GKTurnBasedMatchmakerViewController alloc] initWithMatchRequest:request];
mmvc.turnBasedMatchmakerDelegate = self;
[viewController presentViewController:mmvc animated:YES completion:nil];
}
#pragma mark GKTurnBasedMatchmakerViewControllerDelegate
// A peer-to-peer match has been found, the game should start
- (void)turnBasedMatchmakerViewController:(GKTurnBasedMatchmakerViewController *)viewController didFindMatch:(GKTurnBasedMatch *)match {
[viewController dismissViewControllerAnimated:YES completion:nil];
self.currentMatch = match;
GKTurnBasedParticipant *firstParticipant = [match.participants objectAtIndex:0];
if (firstParticipant.lastTurnDate == NULL) {
    // It's a new game!
    [delegate enterNewGame:match];
} else {
    if ([match.currentParticipant.player isEqual:[GKLocalPlayer localPlayer].playerID]) {
        // It's your turn!
        [delegate takeTurn:match];
    } else {
        // It's not your turn, just display the game state.
        [delegate layoutMatch:match];
    }
    }
}

在开始/加入新测试的匹配之前,您是否删除了测试期间生成的部分填充的参与者列表的旧匹配项? 您可以从 Game Center 应用中手动删除旧比赛,也可以在代码中的适当时间使用"加载涉及本地玩家的回合制比赛并为每个比赛创建比赛对象"的loadMatchesWithCompletionHandler来识别要删除的匹配项。 请参阅 Apple 的文档,以确定正确离开、结束和移除匹配项的步骤。

最新更新