iPhone SDK 3.0 中的 GameKit
我是否需要使用 Peer Picker 在新的 iPhone SDK 3.0 中查找同行?
我真的不想使用它,但我确实想使用点对点蓝牙连接。 是否有任何示例代码可以演示不使用 Peer Picker 的蓝牙连接? Apple 提供的游戏 GKTank 使用了 Peer Picker ,所以我不能使用它。
Do I need to use the Peer Picker to find peers in the new iPhone SDK 3.0?
I don't really want to use it, but I do want to use the peer-to-peer Bluetooth connection. Is there any sample code that demonstrates the Bluetooth connection without using Peer Picker? The game GKTank that Apple provides uses the Peer Picker, so I can't use that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有两种方法可以做到这一点。
第一种方式使用 GameKit API。 首先有两个单独的类,一个实现 GKSessionDelegate 协议并充当 GameKit/蓝牙“处理程序”,另一个充当演示 UI(很可能是某种带有表格视图的视图控制器)。 连接它的方式是处理程序管理 GameKit 通知等,然后调用 UI 上的委托方法,以在对等点连接/断开等时更新表视图。这样,当设备来来去去时,您的选择器列表应该更新以显示谁在附近。
下面是一些可以帮助您入门的代码:
第二种方法是使用标准 Bonjour 服务选择机制。 GameKit 是在 Bonjour 之上实现的(但通过蓝牙而不是 WiFi),因此一旦双方实现网络可达性并连接,它们就会在 Bonjour 下注册,并像任何 Bonjour 服务一样运行。 GameKit 方式可能更简单一些,但如果您已经有 WiFi 代码,它也可以重复用于蓝牙。
There are two ways to do this.
The first way uses GameKit API. You start by having two separate classes, one that implements the
GKSessionDelegate
protocol and acts as a GameKit/Bluetooth "handler" and the other as the presentation UI (most likely some sort of viewcontroller with a tableview). The way you would wire it up is the handler manages the GameKit notifications etc and then calls delegate methods on the UI to update the table view when a peer connects/drops off, etc. That way, as devices come and go, your picker list should update to show who's around.Below is some code to get you started:
The second way to do it is to use standard Bonjour service selection mechanisms. GameKit is implemented on top of Bonjour (but over Bluetooth instead of WiFi) so once the two sides have gone through network reachability with each other and connected they are registered under Bonjour and act like any Bonjour service would. The GameKit way is probably a little easier, but if you already have code for WiFi it can be reused for Bluetooth as well.
为什么你不想使用它?
我不知道有没有一种方法可以自己直接进行蓝牙连接,它提供了通过其他方式查找连接的替代方法。 它提供了一个非常好的系统来在多个 iPod/Touch 之间建立网络,并让您定义关系是真正的对等关系还是主/从关系......
Why do you not want to use it?
I don't know there's a way to directly do a bluetooth connection yourself, and it presents an alternative for finding connections by other means. It provides a pretty nice system to set up a network between a number of iPod/Touches, and lets you define if the relation is truly peer or master / slave...