iOS Multiper连接框架邀请函哈德勒似乎不接受? [英] iOS Multipeer connectivity framework invitationHandler doesn't seem to accept?
问题描述
我第一次使用mutlipeer连接框架,我想要编程(不是辅助类)控制。
一切都按照描述当我在两个独立的设备上运行我的代码,直到广告客户收到委托回调的时候:
浏览客户端的委托回调在发现广告客户时被调用:
- (void)browser:(MCNearbyServiceBrowser *)browser foundPeer:(MCPeerID *)peerID withDiscoveryInfo:(NSDictionary *)info {
[[UIAlertView alloc] initWithTitle:@Peer Found消息:peerID.displayName委托:nil cancelButtonTitle:@OKotherButtonTitles:nil,nil] show];
_session = [[MCSession alloc] initWithPeer:_myPeerID];
_session.delegate = self;
//连接到发现的对等体。
[_browser invitePeer:peerID toSession:_session withContext:nil timeout:30.0];
[_browser stopBrowsingForPeers];
}
然后广告客户的代表回调在收到邀请时被调用:
- (void)advertiser:(MCNearbyServiceAdvertiser *)广告客户didReceiveInvitationFromPeer :( MCPeerID *) peerID withContext:(NSData *)context invitationHandler:(void(^)(BOOL,MCSession *))invitationHandler {
//当我的代码运行时,一切看起来都正确。
// eg。 peerID绝对是我的浏览器客户端的显示名称。
_session = [[MCSession alloc] initWithPeer:_myPeerID];
_session.delegate = self;
//使用简单版本进行测试...接受所有邀请。
inviteHandler(YES,_session);
//停止广告
[_advertiser stopAdvertisingPeer];
}
调用'invitationHandler(YES,_session)'后,看起来像浏览客户端和广告客户端之间从未建立连接。
在客户端设备上的MCSession对象上,我没有收到任何委托回调(一次或两次我收到一个MCSessionStateNotConnected)。我会以为我会收到MCSession委托回调:
- (void)session:(MCSession *)session peer: (MCPeerID *)peerID didChangeState :( MCSessionState)状态;
我错过了什么吗?有其他人遇到这个问题吗?
有一个苹果明显知道的错误。
这是导致发现的原因:为什么我的MCSession对等体随机断开? / a>
您必须实现以下代理回调,即使它在文档中列为可选...
(MCPessionID *)peerID certificateHandler:(void(^)(BOOL accept))certificateHandler((*))
{
certificateHandler(YES);
}
I'm using the mutlipeer connectivity framework for the first time, and I want programmatic ( not with the assistant classes) control.
Everything is working exactly as described when I run my code on two separate devices up until the point when the 'advertiser' receives the delegate callback:
The browsing client's delegate callback is called when it discovers the advertiser:
-(void)browser:(MCNearbyServiceBrowser *)browser foundPeer:(MCPeerID *)peerID withDiscoveryInfo:(NSDictionary *)info{
[[[UIAlertView alloc] initWithTitle:@"Peer Found" message:peerID.displayName delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show];
_session = [[MCSession alloc] initWithPeer:_myPeerID];
_session.delegate = self;
//connect to the discovered peer.
[_browser invitePeer:peerID toSession:_session withContext:nil timeout:30.0];
[_browser stopBrowsingForPeers];
}
Then the advertising client's delegate callback is called when it receives the invite:
-(void)advertiser:(MCNearbyServiceAdvertiser *)advertiser didReceiveInvitationFromPeer:(MCPeerID *)peerID withContext:(NSData *)context invitationHandler:(void (^)(BOOL, MCSession *))invitationHandler{
//when my code runs, everything looks correct here.
//eg. peerID is definitely my 'browser' client's display name etc.
_session = [[MCSession alloc] initWithPeer:_myPeerID];
_session.delegate = self;
//using a simple version for testing... accept all invites.
invitationHandler(YES, _session);
//stop advertising now.
[_advertiser stopAdvertisingPeer];
}
After 'invitationHandler(YES, _session)' is called, it seems like the connection is never established between the 'browsing' client and the 'advertising' client.
I don't ever receive any delegate callbacks (once or twice I received a MCSessionStateNotConnected ) on the MCSession objects on either client device. I would have thought I would have received the MCSession delegate callback:
-(void)session:(MCSession *)session peer:(MCPeerID *)peerID didChangeState:(MCSessionState)state;
Am I missing something? Has anyone else come across this issue?
There is a bug that Apple is aware of apparently.
This is what led to the discovery: Why does my MCSession peer disconnect randomly?
You must implement the following delegate callback even though it is listed as optional in the docs...
- (void) session:(MCSession *)session didReceiveCertificate:(NSArray *)certificate fromPeer:(MCPeerID *)peerID certificateHandler:(void (^)(BOOL accept))certificateHandler
{
certificateHandler(YES);
}
这篇关于iOS Multiper连接框架邀请函哈德勒似乎不接受?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!