使用此代码 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]; } }
请我快速需要帮助:(