我正在尝试通过gamekit将多个设备连接到主机设备,但我能够连接两个设备,并且我能够将数据发送到这两个设备,但是当我连接更多设备时,数据没有&#39转移。在输出控制台中,它显示" BTM:附加到BTServer"并试图通过蓝牙连接它我希望设备连接到WiFi ..我试图连接至少15-20设备..是否有可能将这些设备连接到主机设备??
- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state {
NSLog(@"connection with peer (%@) did change state %d",peerID,state);
switch (state) {
case GKPeerStateAvailable:
if (isConnected == NO) {
[session connectToPeer:peerID withTimeout:20];
}
break;
case GKPeerStateUnavailable:
NSLog(@"session unavailable");
break;
case GKPeerStateConnecting:
NSLog(@"connecting");
break;
case GKPeerStateConnected:
NSLog(@"connected");
if (isServer == YES) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSData *ListData = [defaults objectForKey:@"GlobalList"];
NSError *transmissionError = nil;
[self.serverSession sendData:data toPeers:[NSArray arrayWithObject:peerID] withDataMode:GKSendDataReliable error:&transmissionError];
}
else {
isConnected = YES;
}
break;
case GKPeerStateDisconnected:
NSLog(@"disconnected");
break;
default:
break;
}
}
- (void) receiveData:(NSData *)data fromPeer:(NSString *)peer inSession: (GKSession *)session context:(void *)context {
NSDictionary *receivedMessage = [NSKeyedUnarchiver unarchiveObjectWithData:data];
if ([receivedMessage isKindOfClass:[NSDictionary class]]) {
if([[[receivedMessage allKeys] objectAtIndex:0] isEqualToString:@"GlobalList"]) {
NSArray *hostList = [receivedMessage objectForKey:@"GlobalList"];
for (NSDictionary *lists in hostList)
{
NSString *title = [lists objectForKey:@"Title"];
NSLog (@"Received list %@", title);
}
NSLog(@"total list - %d",hostsList.count);
}
}
}