我有一个使用 GameCenter 进行联网的多人游戏。使用 GKMatch 的 wifi 网络游戏完美运行,但超过 3G 时它们无法连接。我的
-[GKMatchmaker findMatchForRequest:
withCompletionHandler:]
使用错误代码 503 调用完成处理程序块,这不是GKErrorDomainCode
根据该标头。相反,它似乎是一个 HTTP 错误代码。
这是我的代码:
//GKLocalPlayer is already authenticated at this point
_matchRequest = [[[GKMatchRequest alloc] init] autorelease];
[_matchRequest setMinPlayers: 2];
[_matchRequest setMaxPlayers: 2];
GKMatchmaker *matchmaker = [GKMatchmaker sharedMatchmaker];
[matchmaker findMatchForRequest: _matchRequest
withCompletionHandler:
^(GKMatch *match, NSError *error) {
if (error)
{
if ([error code] != GKErrorCancelled)
{
dispatch_async(dispatch_get_main_queue(), ^{
[[[[UIAlertView alloc] initWithTitle:
NSLocalizedString(@"Can't find match.", @"Alert title for when automatching failed")
message: [error localizedDescription]
delegate: nil
cancelButtonTitle: NSLocalizedString(@"OK", @"Button text for OK button")
otherButtonTitles: nil] autorelease] show];
});
}
else
{
NSLog(@"Canceled :(");
}
}
else
{
dispatch_async(dispatch_get_main_queue(), ^{
// do some main-thread stuff specific to my app
_match = [match retain];
[_match setDelegate: self];
});
}
} ];
}
SNJGKLocalPlayerManager
只需将玩家登录到 GameCenter。典型的输出将是第一个 dispatch_async 块中的行中的UIAlertView
“操作无法完成。getLocalConnectionData
超时”。如果我用于NSLog
输出错误代码,则为 503。
如果你已经GameCenter
让多人在 3G 上工作并且不想仔细研究我的代码,请随时分享你的工作代码,我会尝试找出我的问题所在!谢谢!