初めてマルチピア接続フレームワークを使用していますが、プログラムによる (アシスタント クラスではなく) コントロールが必要です。
「広告主」がデリゲート コールバックを受信するまで、2 つの別々のデバイスでコードを実行すると、すべてが説明どおりに機能します。
広告主を検出すると、ブラウジング クライアントのデリゲート コールバックが呼び出されます。
-(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];
}
次に、招待を受信すると、広告クライアントのデリゲート コールバックが呼び出されます。
-(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 オブジェクトでも、デリゲート コールバックを受信したことはありません (1 回か 2 回、 MCSessionStateNotConnected を受信しました)。私は MCSession デリゲート コールバックを受け取ったと思っていたでしょう。
-(void)session:(MCSession *)session peer:(MCPeerID *)peerID didChangeState:(MCSessionState)state;
何か不足していますか?他の誰かがこの問題に遭遇しましたか?