【发布时间】:2014-02-11 09:53:55
【问题描述】:
我是第一次使用多点连接框架,我想要编程(而不是助手类)控制。
当我在两个单独的设备上运行我的代码直到“广告商”收到委托回调时,一切都完全按照描述的那样工作:
浏览客户端的代理回调在发现广告商时被调用:
-(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回调:
-(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)”后,“浏览”客户端和“广告”客户端之间似乎从未建立连接。
我从未在任一客户端设备上的 MCSession 对象上收到任何委托回调(我收到过一次或两次 MCSessionStateNotConnected )。我原以为我会收到 MCSession 委托回调:
-(void)session:(MCSession *)session peer:(MCPeerID *)peerID didChangeState:(MCSessionState)state;
我错过了什么吗?有没有其他人遇到过这个问题?
【问题讨论】:
-
您是否尝试过让浏览器和广告客户保持运行而不是立即停止?
-
是的。不幸的是仍然有同样的行为。
标签: ios objective-c delegates multipeer-connectivity