我知道这个问题以前已经问过,但我只是想知道为什么它不适用于我的具体情况。发送和接收Multipeer连接邀请
我想从一个视图控制器发送multipeer连接的邀请,并在另一个视图控制器上接收它。我发送它的代码是:
[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方法,但我不知道...
我直接从苹果公司的wwdc谈话中复制了MultiPer Connectivity在我的代码中引用的连接...正如你可以看到它是我自己的代码实现,我没有使用广告客户助理或mcbrowserviewcontroller。
有没有人有任何建议,我怎么能得到这个工作?
不错!谢谢! – falky
从我的观察来看,只有SessionDelegate方法是从非主队列中调用的(例如com.apple.MCSession.SyncQueue),NearbyServiceBrowser或者Advertiser's是从主队列中调用的。 – Juguang
@Juguang是的,你说得对 - 我在一段时间后注意到了这一点。忘了所有关于这个问题。编辑 - 谢谢。 – ChrisH