我想使用 GKSession 连接两台设备,一台作为服务器,另一台作为客户端。使用此配置我无法使用 GKPeerPickerController。
我在连接两个设备时遇到问题:
- 仅使用蓝牙:不可能
- 使用WiFi:至少设备之间有一些数据交换,但没有成功连接。
在接口文件中,我有
GKSessionDelegate
GKSession *session;
在实现中,我使用以下代码启动服务器:
session = [[GKSession alloc] initWithSessionID:@"iFood" displayName:nil sessionMode:GKSessionModeClient];
session.delegate = self;
session.available = YES;
客户端开始使用此代码:
session = [[GKSession alloc] initWithSessionID:@"iFood" displayName:nil sessionMode:GKSessionModeServer];
session.delegate = self;
session.available = YES;
如何强制使用蓝牙而不是 WiFi?
我也实现了这些调用:
-(void)session:(GKSession *)session didReceiveConnectionRequestFromPeer:(NSString *)peerID {
NSLog(@"Someone is trying to connect");
}
- (BOOL)acceptConnectionFromPeer:(NSString *)peerID error:(NSError **)error {
NSLog(@"acceptConnectionFromPeer");
}
当我开始时,我把它放到调试器中:
Listening on port 50775
2010-02-19 14:55:02.547 iFood[3009:5103] handleEvents started (2)
当另一个设备开始找到时,我得到了这个:
~ DNSServiceBrowse callback: Ref=187f70, Flags=2, IFIndex=2 (name=[en0]), ErrorType=0 name=00eGs1R1A..Only by Audi regtype=_2c3mugr67ej6j7._udp. domain=local.
~ DNSServiceQueryRecord callback: Ref=17bd40, Flags=2, IFIndex=2 (name=[en0]), ErrorType=0 fullname=00eGs1R1A\.\.Only\032by\032Audi._2c3mugr67ej6j7._udp.local. rrtype=16 rrclass=1 rdlen=18 ttl=4500
** peer 1527211048: oldbusy=0, newbusy=0
~ DNSServiceBrowse callback: Ref=187f70, Flags=2, IFIndex=-3 (name=[]), ErrorType=0 name=00eGs1R1A..Only by Audi regtype=_2c3mugr67ej6j7._udp. domain=local.
GKPeer[186960] 1527211048 service count old=1 new=2
~ DNSServiceQueryRecord callback: Ref=17bd40, Flags=2, IFIndex=-3 (name=[]), ErrorType=0 fullname=00egs1r1a\.\.only\032by\032audi._2c3mugr67ej6j7._udp.local. rrtype=16 rrclass=1 rdlen=18 ttl=7200
** peer 1527211048: oldbusy=0, newbusy=0
~ DNSServiceBrowse callback: Ref=187f70, Flags=2, IFIndex=-3 (name=[]), ErrorType=0 name=00TF5kc1A..Only by Audi regtype=_2c3mugr67ej6j7._udp. domain=local.
~ DNSServiceQueryRecord callback: Ref=188320, Flags=2, IFIndex=-3 (name=[]), ErrorType=0 fullname=00tf5kc1a\.\.only\032by\032audi._2c3mugr67ej6j7._udp.local. rrtype=16 rrclass=1 rdlen=18 ttl=7200
** peer 1723356125: oldbusy=0, newbusy=0
~ DNSServiceQueryRecord callback: Ref=188320, Flags=2, IFIndex=2 (name=[en0]), ErrorType=0 fullname=00TF5kc1A\.\.Only\032by\032Audi._2c3mugr67ej6j7._udp.local. rrtype=16 rrclass=1 rdlen=18 ttl=4500
** peer 1723356125: oldbusy=0, newbusy=0
我在这里缺少什么?
我确定两个设备都启用了蓝牙并连接到同一个 WiFi。
谢谢,
河。