GKPeerPickerController 的连接问题

发布于 2024-11-08 19:22:54 字数 805 浏览 0 评论 0原文

我正在使用 GKSession 和 GKPeerPickerController 开发 iOS 游戏。我发现连接两个 iOS 设备的过程缓慢且不可靠,即使它们彼此相邻。我们将我的设备称为“设备 A”和“设备 B”。

以下是通常发生的情况:

  1. 在每台设备上,我点击应用程序的连接按钮。然后,每个设备都会显示“iPad、iPhone 或 iPod touch”窗口。

  2. 通常很快,两个设备都会注意到对方的存在。

  3. 然后,我告诉其中一个设备(例如设备 A)连接到另一个设备。

  4. 很快,设备 B 的窗口显示设备 A 不可用。

  5. 这就是令人烦恼的地方。大约1秒到没有的一段时间后,设备B上会弹出一个窗口,说设备A想要连接,并询问设备B是否愿意接受连接。

  6. 如果确实弹出上述窗口,则一切正常。但这有时需要很长时间,有时根本不会发生。

我有三台设备,无论使用哪两台,我都会遇到类似的问题。

我能做些什么吗?

我的连接方法非常简单:

-(void) findPeerPickerOpponents {
    GKPeerPickerController *picker;
    picker = [[GKPeerPickerController alloc] init]; 
    picker.delegate = self;
    [picker show]; 
    [self.connectionDelegate disableIdleTimer];
}

I am working on an iOS game with GKSession and GKPeerPickerController. I am finding that the process of connecting two iOS devices is slow and unreliable, even if they are right next to each other. Let's call my devices "device A" and "device B."

Here is what typically happens:

  1. On each device, I hit my app's connect button. Each device then shows the "iPads, iPhones, or iPod touches" window.

  2. Usually pretty quickly, the two devices each notice that the other exists.

  3. I then tell one of the devices (say device A) to connect to the other.

  4. Pretty quickly, device B's window says that device A is not available.

  5. This is where it gets annoying. After a period of time ranging from about 1 second to never, a window pops up on device B saying that device A wants to connect, and asking device B whether or not it wants to accept the connection.

  6. If the above window does pop up, everything proceeds normally. But this sometimes takes a long time, and sometimes does not happen at all.

I have three devices, and I have similar problems no matter which two I am using.

Is there anything I can do about this?

My connection method is pretty straightforward:

-(void) findPeerPickerOpponents {
    GKPeerPickerController *picker;
    picker = [[GKPeerPickerController alloc] init]; 
    picker.delegate = self;
    [picker show]; 
    [self.connectionDelegate disableIdleTimer];
}

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

洛阳烟雨空心柳 2024-11-15 19:22:54

好的,你应该做什么:
- 假设您有设备 A、B 和 C
- 设备 A 正在扫描,设备 B 刚刚开始扫描
- 设备 A 将设备 B 视为新对等方 - 它向 B 发送邀请
- 设备 B 收到邀请 - 它会自动批准它,两个设备都已连接,除了设备出现在大厅中外,不会向用户显示任何通知
- 设备 C 显示
- 设备 A 和 B 尝试连接到它,它们会自动连接并出现在大厅
- 玩家在设备 A 上触摸设备 B
- 设备 A 向 B 发送 WANNAPLAY 数据包
- B 弹出窗口询问玩家是否想和 A 一起玩 - 玩家回答“是”
- 设备 B 向 A 发送 ACCEPTED,并断开除 A 之外的所有人的连接(通过发送 DISCONNECT)
- 设备 A 获得接受并断开除 B 之外的所有人的连接(通过发送 DISCONNECT)
- 设备 C 获得 2x DISCONNECT 并从其大厅中删除 A 和 B

它比标准方法好得多,即使它多了 10 倍的工作 - 我用两种方法都做了,这是一个非常好的解决方案。

ok, what you should do:
- lets say you have device A,B and C
- device A is scanning, device B just started scanning
- device A sees device B as new peer - it sends invite to B
- device B gets invite - it automaticaly approves it, both devices are connected, no notification is presented to user, except that devices appear in the lobby
- device C shows up
- devices A and B try to connect to it, they get autoconnected and show up at lobby
- player touches device B on device A
- device A sends WANNAPLAY packet to B
- B presents pop up asking if player wants play with A - player answers YES
- device B sends ACCEPTED to A and disconnects everybody except A (by sending DISCONNECT)
- device A gets ACCEPTED and disconnects everybody except B (by sending DISCONNECT)
- device C gets 2x DISCONNECT and removes A and B from it's lobby

It works MUCH BETTER than the standard approach, even if its like 10x more work - I did it both ways and it's a very good solution.

能否归途做我良人 2024-11-15 19:22:54

我完全放弃了peerPickerController。查看 Apple 的 GKRocket 示例代码。 - 使用 GKSession 和同行的表格视图。现在我的设备上有点问题,原因我不清楚,但我使用了基本类:GameLobby 和 SessionManager 来让设备连接得很好。还有一个优点是不限制您只能与一位同行。

I gave up on peerPickerController completely. Check out Apple's GKRocket example code. - Uses GKSession and tableviews of peers. It is a bit buggy on my devices right now, for reasons I am not clear on, but I used the basic classes: GameLobby and SessionManager to get devices hooking up pretty well. Also has the advantage of not restricting you to one peer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文