gpt4 book ai didi

ios - 游戏中心 : match delegate’s not called after finding a match

转载 作者:可可西里 更新时间:2023-11-01 04:54:55 24 4
gpt4 key购买 nike

我正在尝试使用游戏中心:多人游戏

到目前为止,玩家正在对 Game center 进行身份验证,他们可以发送/读取分数和成就。对于多人游戏功能,我尝试了两种方法: - 使用游戏中心界面寻找匹配项。 - 以编程方式查找匹配项。

对于这两种方式,我都遇到了以下问题:未调用匹配委托(delegate)的 match:player:didChangeState: 方法。在 apple 文档中,声明如果一个玩家连接或断开连接,则调用此委托(delegate)。

在我的例子中,这个委托(delegate)从未被调用过。我想我错过了一步。在执行我的委托(delegate)之后(如 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”。您已连接,恕不另行通知,您可以开始接收数据。我从来没有尝试发送/接收数据,因为我首先期待的是事件,但我确实有一次错误地发送了一些东西,但它成功了。

- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *) match {    
//Dismiss window
[self dismissModalViewControllerAnimated:YES];

//Retain match
self.myMatch = match;

//Delegate
myMatch.delegate = self;


//Flag
matchStarted = TRUE;

//Other stuff
}

- (void)match:(GKMatch *)match player:(NSString *)playerID didChangeState:(GKPlayerConnectionState)state {
//This code gets called only on auto-match
}

以上代码按预期工作。

关于ios - 游戏中心 : match delegate’s not called after finding a match,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4794276/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com