Game Kit를 사용하여 Bluetooth를 통해 두 개의 장치를 연결하려고합니다. 첫 번째 장치가 내부에 다음 코드를 갖는 프로그램을 실행한다 : 제 2 디바이스 전용의 다음 부분으로, 상기와 동일한 코드를 사용하는 다른 응용 프로그램을 실행하는내 게임 장치가이 게임 키트 연결 코드를 사용하여 서로를 찾을 수없는 이유는 무엇입니까?
-(void)connect
{
GKPeerPickerController* picker;
picker = [[GKPeerPickerController alloc] init];
picker.delegate = self;
//picker.connectionTypesMask = GKPeerPickerConnectionTypeNearby;
picker.connectionTypesMask = GKPeerPickerConnectionTypeNearby;
[picker show];
}
- (void)viewDidLoad {
[super viewDidLoad];
peerStatus = kServer;
gamePacketNumber = 0;
currentSession = nil;
gamePeerId = nil;
NSString *uid = [[UIDevice currentDevice] uniqueIdentifier];
gameUniqueID = [uid hash];
[self connect];
}
- (void)peerPickerController:(GKPeerPickerController *)picker didSelectConnectionType:(GKPeerPickerConnectionType)type {
// GKSessionModeClient
// GKSessionModeServer
[self.currentSession initWithSessionID:kTankSessionID displayName:nil sessionMode:GKSessionModeClient];
currentSession.available = YES;
currentSession.delegate = self;
}
- (void)peerPickerController:(GKPeerPickerController *)picker didConnectPeer:(NSString *)peerID toSession:(GKSession *)session
{
self.gamePeerId= peerID;
//self.currentSession = session;
self.currentSession.delegate = self;
[self.currentSession setDataReceiveHandler: self withContext:nil];
// Remove the picker.
picker.delegate = nil;
[picker dismiss];
[picker autorelease];
// Start your game
}
- (void)peerPickerControllerDidCancel: (GKPeerPickerController *)picker
{
NSLog(@"peerPickerControllerDidCancel");
picker.delegate = nil;
[picker autorelease];
}
- (void)session: (GKSession*)session peer:(NSString*)peerID didChangeState:(GKPeerConnectionState)state
{
NSLog(@"finding and connecting to others sessions");
if(state == GKPeerStateAvailable){
NSLog(@"aviable and ready to conect");
[session connectToPeer:peerID withTimeout:60];
session.available =NO; //put YES si volem multiconexions sino es tancarà la sesio en conectarse 2
}
}
- (void)session:(GKSession *)session didReceiveConnectionRequestFromPeer:(NSString *)peerID{
NSLog(@"lisetn for others sessions");
NSError *error=nil;
if(amAcceptingConnetions){
if(![session acceptConnectionFromPeer:peerID error:&error]){
//Handler error
}
}else{
[session denyConnectionFromPeer:peerID];
}
}
것은 변경됨
[self.currentSession initWithSessionID:kTankSessionID displayName:nil sessionMode:GKSessionModeServer];
두 장치 모두 다른 장치를 검색 중임을 나타내지 만 두 장치는 서로를 인식하지 못합니다. 여기서 무엇이 잘못 될 수 있습니까?