发送和接收与Multipeer连接发出邀请 [英] Sending and Receiving an Invitation with Multipeer Connectivity
问题描述
我知道这个问题已经被问过,但我只是想知道为什么它不在我的具体情况的工作。
I know this question has been asked before, but I was just wondering why it isn't working in my particular case.
我试图从一个视图控制器发送来自multipeer连接的邀请并接受它在另一个上。我的code发送,它是:
I am trying to send an invitation from multipeer connectivity from one view controller and receive it on another. My code for sending it is:
[self invitePeer:selectedPeerID toSession:self.mySession withContext:nil timeout:timeInterval ];
和方法仅仅是空白的:
- (void)invitePeer:(MCPeerID *)peerID toSession:(MCSession *)session withContext:(NSData *)context timeout:(NSTimeInterval)timeout
{
}
我的code,用以接收和邀请是:
My code for receiving and invitation is:
- (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只是保持高亮显示...
I have all the delegate methods correctly set up as well as the same service types and that. But when i try to initiate the session, the tableviewcell which i click on just remains highlighted...
我想我必须把东西在invitePeer toSession方法,但我不知道...
I'm thinking I have to put something in the invitePeer toSession method but I'm not sure...
我直接从这个在我的code引用上Multipeer连接苹果的WWDC谈话复制......正如你可以看到它是我自己实现的code的,我没有使用广告商助手或mcbrowserviewcontroller
I copied this directly from Apple's wwdc talk on Multipeer Connectivity referenced in my code... As you can see it is my own implementation of the code and I am not using an advertiser assistant or the mcbrowserviewcontroller.
有没有人有任何建议,我怎么能得到这个工作?
Does anyone have any suggestions as to how I can get this to work??
推荐答案
的 invitePeer:toSession:withContext:超时:
方法是由 MCNearbyServiceBrowser实施
,所以你应该调用一个浏览器而不是自
。
The invitePeer: toSession: withContext: timeOut:
method is implemented by MCNearbyServiceBrowser
so you should be calling that on the browser not on self
.
[浏览器invitePeer:selectedPeerID toSession:self.mySession withContext:无超时:一个时间间隔];
不过,如果你想排除接受邀请我跳过警报视图现在,只接受在 didReceiveInvitation马上
广告主委托的回调
However, if you're trying to troubleshoot accepting invitations I'd skip the alert view for now and just accept right away in the didReceiveInvitation:
callback of the advertiser delegate.
修改
我倒是本来指出,从Multipeer连接类委托回调排在私人队列但@Juguang指出,这仅仅是 MCSessionDelegate
回调的情况。
I'd originally stated that the delegate callbacks from Multipeer Connectivity classes came in on private queues but as @Juguang pointed out this is only the case for MCSessionDelegate
callbacks.
这篇关于发送和接收与Multipeer连接发出邀请的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!