我知道以前有人问过这个问题,但我只是想知道为什么它在我的特定情况下不起作用。
我正在尝试从一个视图控制器发送来自多对等连接的邀请并在另一个视图控制器上接收它。我的发送代码是:
[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 仍然突出显示......
我想我必须在invitePeer toSession 方法中添加一些东西,但我不确定......
我直接从 Apple 在我的代码中引用的关于 Multipeer Connectivity 的 wwdc 演讲中复制了此内容……正如您所见,这是我自己的代码实现,我没有使用广告商助理或 mcbrowserviewcontroller。
有人对我如何让它工作有任何建议吗?