0

使用此代码 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];
    }
}

请我快速需要帮助:(

4

1 回答 1

1

我最近遇到了同样的问题。您应该使用MCBrowserViewController。看看我的回答here

于 2013-10-26T09:21:27.347 回答