ios - GKPeerPickerController 已弃用

标签 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];
    }
}

拜托,我需要快速帮助:(

最佳答案

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

关于ios - GKPeerPickerController 已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19438570/

相关文章:

ios - 重写 UICollectionViewFlowLayout 问题中的layoutAttributesForElementsInRect

objective-c - otool for armv7 的错误方法实现地址?

Android 排行榜和成就弃用

Android - 从 PDU 已弃用的 API 创建 SMS?

iphone - 实现视频通话的问题?

ios - 为什么 GLKView 没有上下文?

ios - 字典中每个键的多个值

c# - 在 WCF 契约(Contract)中标记弃用的字段

ios - 数组中的值不更新

iOS Sharepoint App 登录错误