通过 3G/WWAN 进行游戏中心多人游戏 - getLocalConnectionData 超时

发布于 2024-12-25 16:14:21 字数 2025 浏览 1 评论 0原文

我有一个使用 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。典型的输出是一个 UIAlertView ,显示第一个dispatch_async 块中的行“操作无法完成。getLocalConnectionData 超时”。如果我使用 NSLog 输出错误代码,则为 503。

如果您已经让 GameCenter 多人游戏在 3G 上运行并且不想仔细研究我的代码,请感受一下免费分享您的工作代码,我会尽力找出我的代码出了问题!谢谢!

I have a multiplayer game that uses GameCenter for networking. Network games over wifi using GKMatch work perfectly, but over 3G they never connect. My

-[GKMatchmaker findMatchForRequest:
withCompletionHandler:]

completion handler block is invoked with an error code 503, which isn't a GKErrorDomainCode according to that header. Instead it appears to be an HTTP error code.

Here's my code:

//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 just logs the player into GameCenter. Typical output from this would be a UIAlertView saying "The operation could not be completed. getLocalConnectionData timed out" from the line in the first dispatch_async block. If I use NSLog to output the error code, it's 503.

If you've gotten GameCenter multiplayer to work over 3G and don't want to pore over my code, feel free to share your working code and I'll try to find where mine goes wrong! Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文