我知道这个问题之前已经被问过,但我只是想知道为什么它在我的特定情况下不起作用。
我正在尝试从一个视图控制器的多点连接发送邀请,并在另一个视图控制器上接收它。我的发送代码是:
[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。
有人对我如何让它发挥作用有任何建议吗?