Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Kingbombs

macrumors member
Original poster
Jun 24, 2009
98
0
Currently i am using the GameKit framework to establish a 2 player connection over bluetooth
Everything is working fine except the disconnect

When i disconnect, the player who hits the disconnect button disconnects fine and can connect to other devices or do what ever and its all ok
the player who didn't press the disconnect button, his app crashes, now i think what happens is it waits for the timeout to happen and disconnect themselves that way
But i would like it be kinda instant in what is happening and to disconnect immediately as well

heres some code samples:
In my recieve data method:
Code:
if (myNumber == 5)  // this just checks they have asked to disconnect
	{
		[gameSession disconnectFromAllPeers];
		//[gameSession setDisconnectTimeout:0.001];
	}
Neither of these works, tried to set timout period very short but seemed to make no difference and disconnectFromAllPeers makes it crash to

In my method:
- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state
I have this code under disconnect:
Code:
case GKPeerStateDisconnected:
			[self.picker dismiss];
			[self.gameSession release];
			peerStatus = kServer;
			break;

im guessing i am missing something,
if it makes any difference in my - (void)peerPickerControllerDidCancel:(GKPeerPickerController *)picker method i have:
Code:
[gameSession disconnectFromAllPeers];
	gameSession.available = NO;
	[gameSession setDataReceiveHandler: nil withContext: nil];
	gameSession.delegate = nil;
	[gameSession release];

Finally in my IBAtion for when the disconnect button is pressed i have this code:
Code:
[self mySendData:5];
	[gameSession disconnectFromAllPeers];

If anyone can help that would be very good,
But i am having troubles just trying to find much information on google and no one seems to say these problems
 
ITs fixed now need to put this:
Code:
[gameSession disconnectFromAllPeers];
	gameSession.available = NO;
	[gameSession setDataReceiveHandler: nil withContext: nil];
	gameSession.delegate = nil;
	[gameSession release];
in the recieve data section,
and had to remove the part form picker:didCancel
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.