在iOS游戏套件中-首次连接设备问题
每次我在安装应用程序后第一次尝试通过Bluetooh连接设备时,连接花费的时间太长,有时连接被拒绝 这是我的密码:在iOS游戏套件中-首次连接设备问题,ios,Ios,每次我在安装应用程序后第一次尝试通过Bluetooh连接设备时,连接花费的时间太长,有时连接被拒绝 这是我的密码: (void)setUpSession { @try { if(mTimeOutTimer) { [mTimeOutTimer invalidate]; mTimeOutTimer = nil; } self.mConnectionState = ConnectionState
(void)setUpSession {
@try {
if(mTimeOutTimer) {
[mTimeOutTimer invalidate];
mTimeOutTimer = nil;
}
self.mConnectionState = ConnectionStateDisconnected;
if(!mPeerPickerController) {
mPeerPickerController = [[GKPeerPickerController alloc] init];
mPeerPickerController.delegate = self;
mPeerPickerController.connectionTypesMask = GKPeerPickerConnectionTypeNearby;
}
//Present Peer Picker.
[mPeerPickerController show];
}
@catch (NSException *exception) {
NSLog(@"Expception Occured at path -> BlueToothManager/setUpSession");
NSLog(@"Exception Name -> %@",[exception name]);
NSLog(@"Exception Reason -> %@",[exception reason]);
}
}
(GKSession *)peerPickerController:(GKPeerPickerController *)picker sessionForConnectionType:(GKPeerPickerConnectionType)type {
NSString *deviceName = [[UIDevice currentDevice] name];
GKSession* gkSession = [[GKSession alloc] initWithSessionID:@"BluetoothStreamingVideo" displayName:deviceName sessionMode:GKSessionModePeer];
gkSession.delegate = self;
if(self.mGameKitSession) {
[self.mGameKitSession disconnectFromAllPeers];
if([self.mGameKitSession isAvailable]) {
[self.mGameKitSession setAvailable:FALSE];
}
[self.mGameKitSession setDataReceiveHandler:nil withContext:nil];
self.mGameKitSession = nil;
}
self.mGameKitSession = gkSession;
return [gkSession autorelease];
}
但一旦连接设置好,下一次连接就设置得很好,不会持续很长时间