通过多点连接发送和接收邀请

2024-02-22

我知道这个问题之前已经被问过,但我只是想知道为什么它在我的特定情况下不起作用。

我正在尝试从一个视图控制器的多点连接发送邀请,并在另一个视图控制器上接收它。我的发送代码是:

[self invitePeer:selectedPeerID toSession:self.mySession withContext:nil timeout:timeInterval ];

并且方法只是空白:

 - (void)invitePeer:(MCPeerID *)peerID toSession:(MCSession *)session withContext:(NSData *)context timeout:(NSTimeInterval)timeout 
 {

 }

我的接收和邀请代码是:

 - (void)advertiser:(MCNearbyServiceAdvertiser *)advertiser didReceiveInvitationFromPeer:(MCPeerID *)peerID withContext:(NSData *)context invitationHandler:(void(^)(BOOL accept, MCSession *session))invitationHandler 
 {

      // http://down.vcnc.co.kr/WWDC_2013/Video/708.pdf  -- wwdc tutorial, this part is towards the end (p119)

      self.arrayInvitationHandler = [NSArray arrayWithObject:[invitationHandler copy]];
      // ask the user
      UIAlertView *alertView = [[UIAlertView alloc]
                          initWithTitle:peerID.displayName
                          message:@"Would like to create a session with you"
                          delegate:self
                          cancelButtonTitle:@"Decline" otherButtonTitles:@"Accept", nil];
      [alertView show];


  }

 - (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
 {
      // retrieve the invitationHandler and  check whether the user accepted or declined the invitation...

      BOOL accept = (buttonIndex != alertView.cancelButtonIndex) ? YES : NO;

      // respond
      if(accept) {
              void (^invitationHandler)(BOOL, MCSession *) = [self.arrayInvitationHandler objectAtIndex:0];
    invitationHandler(accept, self.mySession);
          }
          else 
          {
              NSLog(@"Session disallowed");
          }
  }

我已正确设置所有委托方法以及相同的服务类型等等。但是当我尝试启动会话时,我单击的 tableviewcell 仍然突出显示......

我想我必须在 informPeer toSession 方法中添加一些内容,但我不确定......

我直接从我的代码中引用的 Apple 关于 Multipeer Connectivity 的 wwdc 演讲中复制了此内容...如您所见,这是我自己的代码实现,我没有使用广告商助手或 mcbrowserviewcontroller。

有人对我如何让它发挥作用有任何建议吗?


The invitePeer: toSession: withContext: timeOut:方法的实现是MCNearbyServiceBrowser所以你应该在浏览器上调用它而不是self.

[browser invitePeer:selectedPeerID toSession:self.mySession withContext:nil timeout:timeInterval ];

但是,如果您尝试解决接受邀请的问题,我会暂时跳过警报视图,直接在didReceiveInvitation:广告商委托的回调。

Edit

我最初声明来自 Multipeer Connectivity 类的委托回调进入私有队列,但正如 @Juguang 指出的那样,这只适用于MCSessionDelegate回调。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

通过多点连接发送和接收邀请 的相关文章

随机推荐