我试图使用游戏中心后称为:多玩家游戏中心:匹配委托的未找到匹配
截至目前,玩家要进行身份验证游戏中心,它们可以发送/读取的分数,并acheivements。 对于多人游戏功能,我尝试了两种方法: - 使用游戏中心界面来查找比赛。 - 以编程方式查找匹配项。
对于这两种方式,我有以下问题:匹配委托的匹配:player:didChangeState:方法不被调用。 在苹果文档中,声明如果一个玩家连接或断开连接,则会调用此代理。
在我的情况下,这个委托永远不会被调用。我认为我错过了一步。 这里是在执行我的委托之后(如apple doc中指定的)。
- (void)match:(GKMatch *)match player:(NSString *)playerID didChangeState:(GKPlayerConnectionState)state
{
switch (state)
{
case GKPlayerStateConnected:
// handle a new player connection.
break;
case GKPlayerStateDisconnected:
// a player just disconnected.
break;
}
if (!self.matchStarted && match.expectedPlayerCount == 0)
{
self.matchStarted = YES;
// handle initial match negotiation.
}
}
并且还找到匹配的代码。
-(void) findProgrammaticMatch
{
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = 2;
request.maxPlayers = 2;
[[GKMatchmaker sharedMatchmaker] findMatchForRequest:request
withCompletionHandler:^(GKMatch *FoundMatch, NSError *error)
{
if (error)
{
// Process the error.
StatusLabel.text = @"Match Not Found";
}
else if (FoundMatch != nil)
{
MultiPlayerMatch = FoundMatch; // Use a retaining property to retain the match.
StatusLabel.text = @"Match Found";
MultiPlayerMatch.delegate = self; // start!
// Start the match.
// Start the game using the match.
[self StartMatch];
}
}];
}
感谢您的帮助。
我不相信这是真的。我刚刚测试过自动匹配,didChangeState从不会触发。只有didFindMatch。我认为didChangeState可能只有在玩家进入GKPlayerStateUnknown然后回来,或者他们被添加到进行中的比赛时才会发生。 – 2014-12-02 09:23:51