使用 GameKit 连接第三台设备
我现在正在基础水平上使用 GameKit。我能够连接两个设备并在它们之间发送消息。
我有 3 个设备,我们将它们称为设备 A、B 和 C。
我能够将 A 连接到 B、A 连接到 C、B 连接到 C,作为单独的设置。
如果我将 A 连接到 B,然后尝试将 B 连接到 C,设备 C 将显示设备 B 可用,但设备 B 继续旋转并说“正在寻找可用的 iPod、iPhone...”
在peerPickerController 中: sessionForConnectionType: ,当我尝试将 B 连接到 C 时,我试图让设备 B 重用它在连接到 A 时使用的相同 GKSession
...因为如果我在设备 B 上创建一个新会话,它能够连接到设备 C,但会断开与设备 A 的连接。
以下是 sessionForConnectionType
:
-(GKSession*)peerPickerController:(GKPeerPickerController *)picker sessionForConnectionType:(GKPeerPickerConnectionType)type {
// session is a synthesized GKSession
if (session == nil) {
session = [[GKSession alloc] initWithSessionID:nil displayName:@"" sessionMode:GKSessionModePeer];
session.delegate = self;
}
return session;
}
I am using GameKit on a basic level right now. I am able to connect two devices and send messages between them.
I have 3 devices, we'll call them device A, B and C.
I am able to connect A to B, A to C, and B to C, as individual setups.
If I connect A to B, then attempt to connect B to C, Device C will show that Device B is available, but device B continues to spin and say "Looking for available iPod, iPhones..."
In peerPickerController:sessionForConnectionType:
, when I am attempting to connect B to C, I am trying to have device B reuse its same GKSession
that it is using in its connection to A... because if I create a new session on device B, it is able to connect to Device C but drops the connection to device A.
Here is the sessionForConnectionType
:
-(GKSession*)peerPickerController:(GKPeerPickerController *)picker sessionForConnectionType:(GKPeerPickerConnectionType)type {
// session is a synthesized GKSession
if (session == nil) {
session = [[GKSession alloc] initWithSessionID:nil displayName:@"" sessionMode:GKSessionModePeer];
session.delegate = self;
}
return session;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终选择了服务器/客户端设置,这更易于管理。这样,就只有一个 Server PeerID,而不是每个连接都有一个 Server PeerID。我找不到很多好的例子,所以我在这里包含了基本的 GameKit 服务器/客户端代码。
I ended up going with a Server / Client setup, which is easier to manage. This way, there is only one Server PeerID, as opposed to a Server PeerID for every connection. I wasn't able to find many good examples, so I've included the basic GameKit Server / Client code here.