【问题标题】:Binding request failed in MPCMPC 中的绑定请求失败
【发布时间】:2017-03-05 14:51:59
【问题描述】:
#import "Session.h"
#import <MultipeerConnectivity/MultipeerConnectivity.h>

@interface Session () <MCSessionDelegate,MCBrowserViewControllerDelegate>
@property (strong,nonatomic) MCSession *session;
@property (strong,nonatomic) MCAdvertiserAssistant *advertiser;
@property (strong,nonatomic) MCPeerID *peerId;
@end

@implementation Session

#pragma mark - Initialiser(s)

//Setting the name of the peer
-(id)initWithDisplayName:(NSString *)name{
    self = [super init];
    self.peerId = [[MCPeerID alloc]initWithDisplayName:name];
    return self;
}

#pragma mark - Property accessor(s)

//Late initialisation
-(MCSession *)session{
    if(!_session){
        _session = [[MCSession alloc]initWithPeer:self.peerId securityIdentity:nil encryptionPreference:MCEncryptionNone];
        _session.delegate = self;
    }
    return _session;
}

#pragma mark - MCSessionDelegate Methods

//Detecting the change in the connection state of the peer
-(void)session:(MCSession *)session peer:(MCPeerID *)peerID didChangeState:(MCSessionState)state{
    if (state == MCSessionStateConnecting) {
        NSLog(@"Connecting to %@", peerID.displayName);
    } else if (state == MCSessionStateConnected) {
        NSLog(@"Connected to %@", peerID.displayName);
    } else if (state == MCSessionStateNotConnected) {
        NSLog(@"Disconnected from %@", peerID.displayName);
    }
}

//Handling the data recieved by the session
-(void)session:(MCSession *)session didReceiveData:(NSData *)data fromPeer:(MCPeerID *)peerID{
    [self.delegate session:self didRecieveData:data];
}

//Handling the stream recieved by the session
-(void)session:(MCSession *)session didReceiveStream:(NSInputStream *)stream withName:(NSString *)streamName fromPeer:(MCPeerID *)peerID{
    [self.delegate session:self didRecieveAudioStream:stream];
}

//Started recieving stream
-(void)session:(MCSession *)session didStartReceivingResourceWithName:(NSString *)resourceName fromPeer:(MCPeerID *)peerID withProgress:(NSProgress *)progress{

}

//Finished recieving stream
-(void)session:(MCSession *)session didFinishReceivingResourceWithName:(NSString *)resourceName fromPeer:(MCPeerID *)peerID atURL:(NSURL *)localURL withError:(NSError *)error{

}

-(void)session:(MCSession *)session didReceiveCertificate:(NSArray *)certificate fromPeer:(MCPeerID *)peerID certificateHandler:(void (^)(BOOL))certificateHandler{
    certificateHandler(YES);
    NSLog(@"Recieved a certificate");
}

#pragma mark - MCBrowserViewControllerDelegate methods

//Browser view controller has completd
-(void)browserViewControllerDidFinish:(MCBrowserViewController *)browserViewController{
    [browserViewController dismissViewControllerAnimated:YES completion:nil];
}

//Browser view controller is cancelled
-(void)browserViewControllerWasCancelled:(MCBrowserViewController *)browserViewController{
    [browserViewController dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - Advertising and Browsing

//Initialise the browser
-(MCBrowserViewController *)browserViewControllerForServiceType:(NSString *)type{
    MCBrowserViewController *browser = [[MCBrowserViewController alloc]initWithServiceType:type session:self.session];
    browser.delegate = self;
    return browser;
}

//Starting the advertiser for the particular service type
-(void)startAdvertisingForServiceType:(NSString *)type discoveryInfo:(NSDictionary *)info{
    if(!self.advertiser)
        self.advertiser = [[MCAdvertiserAssistant alloc]initWithServiceType:type discoveryInfo:info session:self.session];
    [self.advertiser start];
}

//Stoping the advertiser
-(void)stopAdvertising{
    [self.advertiser stop];
}

#pragma mark - Misc methods

//Creating the output stream in the current session
-(NSOutputStream *)outputStreamForPeer:(MCPeerID *)peerId{
    NSError *error;
    NSOutputStream *stream = [self.session startStreamWithName:@"Music" toPeer:peerId error:&error];
    if(error)
        NSLog(@"%@",[error userInfo].description);
    return stream;
}

//Sending the date to all the peers connected to the session
-(void)sendData:(NSData *)data{
    NSError * error;
    [self.session sendData:data toPeers:self.session.connectedPeers withMode:MCSessionSendDataUnreliable error:&error];
    if(error)
        NSLog(@"%@",[error userInfo].description);
}

-(NSArray *)connectedPeers{
    return [self.session connectedPeers];
}
@end

这是我在 mpc 中的会话文件。我得到的错误是

Project[7347:876615] [GCKSession] 未处于连接状态,因此放弃通道 [0] 上的参与者 [12ECD777]。 和

Project[7347:876615] [ViceroyTrace] [ICE][ERROR] ICEStopConnectivityCheck() 没有找到带有呼叫 ID (317511543) 的 ICE 检查

Project[7347:876751] [ViceroyTrace] [ICE][ERROR] 发送 BINDING_REQUEST 失败(C01A0041)。

需要帮助

【问题讨论】:

  • 如果需要更多信息,请告诉我
  • 我正在使用 ios 中的一个名为 MPC 的类。所以它也可以在swift中使用。这就是为什么我认为快速的人也可能会有所帮助@EricAya

标签: ios multipeer-connectivity


【解决方案1】:

我前段时间遇到过这些问题,结果我犯了两个错误:

  1. 永远不要复制MCPeerID 对象:一旦我将在MCNearbyServiceBrowserDelegatefoundPeer 调用中收到的MCPeerID 对象存储为字典的键,它复制了该对象。然后当后来我使用该对等 ID 通过MCNearbyServiceBrowser 邀请对等时,连接将失败,因为MCPeerID 是一个副本。
  2. 如果您的设备之一是 iOS 模拟器,请确保您的防火墙没有在操作系统级别阻止外部连接。

我感觉到你的痛苦...... MCFramework 日志无济于事。 我希望这会有所帮助。祝你好运。

【讨论】:

    猜你喜欢
    • 2017-02-18
    • 2014-05-08
    • 1970-01-01
    • 1970-01-01
    • 2019-12-26
    • 2022-01-16
    • 2017-04-13
    • 1970-01-01
    相关资源
    最近更新 更多