我在使用此代码时出现问题GKPeerPickerController和GKSession以及GKPeerConnectionState
我遇到的错误:不推荐使用GKPeerPickerController:首先在IOS 7中弃用
我的代码是:
-(void) receiveData:(NSData *)data fromPeer:(NSString *)peer inSession:(GKSession *)session context:(void *)context { NSKeyedUnarchiver *archiver=[[NSKeyedUnarchiver alloc]initForReadingWithData:data]; NSString *str=[archiver decodeObjectForKey:@"Text"]; [self adicionarTexto:str fuiEu:NO]; } -(void)peerPickerController:(GKPeerPickerController *)picker didConnectPeer:(NSString *)peerID toSession:(GKSession *) session { currentSession = session; session.delegate = self; [session setDataReceiveHandler:self withContext:nil]; picker.delegate = nil; [picker dismiss]; } -(void)peerPickerControllerDidCancel:(GKPeerPickerController *)picker{ picker.delegate = nil; conectado=NO; } -(void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state { if (state==GKPeerStateConnected) { conectado=YES;
}else{
conectado=NO;
}
[self atualizarBarra];
}
和
-(void)peerPickerController:(GKPeerPickerController *)picker didConnectPeer:(NSString *)peerID toSession:(GKSession *) session {
currentSession = session; session.delegate = self; [session
setDataReceiveHandler:self withContext:nil]; picker.delegate = nil;
[picker dismiss]; }
并且
-(void)conectar{ if (conectado==NO) { BTpicker = [[GKPeerPickerController alloc] init]; BTpicker.delegate = self; BTpicker.connectionTypesMask = GKPeerPickerConnectionTypeNearby; [BTpicker show]; }else { [currentSession disconnectFromAllPeers]; } }
我需要快速帮助:(