iOS Multipeer 连接框架invitationHandler 似乎不接受?

iOS Multipeer connectivity framework invitationHandler doesn#39;t seem to accept?(iOS Multipeer 连接框架invitationHandler 似乎不接受?)
本文介绍了iOS Multipeer 连接框架invitationHandler 似乎不接受?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一次使用多点连接框架,我想要编程(而不是助手类)控制.

I'm using the mutlipeer connectivity framework for the first time, and I want programmatic ( not with the assistant classes) control.

当我在两个单独的设备上运行我的代码直到广告商"收到委托回调时,一切都完全按照描述的那样工作:

Everything is working exactly as described when I run my code on two separate devices up until the point when the 'advertiser' receives the delegate callback:

浏览客户端的代理回调在发现广告商时被调用:

The browsing client's delegate callback is called when it discovers the advertiser:

-(void)browser:(MCNearbyServiceBrowser *)browser foundPeer:(MCPeerID *)peerID withDiscoveryInfo:(NSDictionary *)info{
    [[[UIAlertView alloc] initWithTitle:@"Peer Found" message:peerID.displayName delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show];

    _session = [[MCSession alloc] initWithPeer:_myPeerID];
    _session.delegate = self;

    //connect to the discovered peer.
    [_browser invitePeer:peerID toSession:_session withContext:nil timeout:30.0];
    [_browser stopBrowsingForPeers];

}

然后广告客户端收到邀请后调用delegate回调:

Then the advertising client's delegate callback is called when it receives the invite:

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

    //when my code runs, everything looks correct here. 
    //eg. peerID is definitely my 'browser' client's display name etc.

    _session = [[MCSession alloc] initWithPeer:_myPeerID];
    _session.delegate = self;

    //using a simple version for testing... accept all invites.
    invitationHandler(YES, _session);

    //stop advertising now.
    [_advertiser stopAdvertisingPeer];
}

调用invitationHandler(YES, _session)"后,浏览"客户端和广告"客户端之间似乎从未建立连接.

After 'invitationHandler(YES, _session)' is called, it seems like the connection is never established between the 'browsing' client and the 'advertising' client.

我从未在任一客户端设备上的 MCSession 对象上收到任何委托回调(我收到过一次或两次 MCSessionStateNotConnected ).我原以为我会收到 MCSession 委托回调:

I don't ever receive any delegate callbacks (once or twice I received a MCSessionStateNotConnected ) on the MCSession objects on either client device. I would have thought I would have received the MCSession delegate callback:

-(void)session:(MCSession *)session peer:(MCPeerID *)peerID didChangeState:(MCSessionState)state;

我错过了什么吗?有没有其他人遇到过这个问题?

Am I missing something? Has anyone else come across this issue?

推荐答案

Apple 显然意识到了一个错误.

There is a bug that Apple is aware of apparently.

这是导致发现的原因:为什么我的 MCSession 对等端随机断开连接?

您必须实现以下委托回调,即使它在文档中列为可选...

You must implement the following delegate callback even though it is listed as optional in the docs...

- (void) session:(MCSession *)session didReceiveCertificate:(NSArray *)certificate fromPeer:(MCPeerID *)peerID certificateHandler:(void (^)(BOOL accept))certificateHandler
{
 certificateHandler(YES);
}

这篇关于iOS Multipeer 连接框架invitationHandler 似乎不接受?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)