不推荐使用GKPeerPickerController

时间:2013-10-17 22:42:51

标签: ios objective-c deprecated gkpeerpickercontroller

我在使用此代码时出现问题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];
    }
}

我需要快速帮助:(

1 个答案:

答案 0 :(得分:1)

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