我是第一次使用多点连接框架,我想要编程(而不是助手类)控制.
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];
}
然后广告客户端收到邀请后调用delegate回调:
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];
}
调用invitationHandler(YES, _session)"后,浏览"客户端和广告"客户端之间似乎从未建立连接.
After 'invitationHandler(YES, _session)' is called, it seems like the connection is never established between the 'browsing' client and the 'advertising' client.
我从未在任一客户端设备上的 MCSession 对象上收到任何委托回调(我收到过一次或两次 MCSessionStateNotConnected ).我原以为我会收到 MCSession 委托回调:
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?
Apple 显然意识到了一个错误.
There is a bug that Apple is aware of apparently.
这是导致发现的原因:为什么我的 MCSession 对等端随机断开连接?
您必须实现以下委托回调,即使它在文档中列为可选...
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 Multipeer 连接框架invitationHandler 似乎不接受?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!