我用这个在父类中创建一个 MCSession:
- (void) setUpMultipeer{
// Setup peer ID
self.myPeerID = [[MCPeerID alloc] initWithDisplayName:[UIDevice currentDevice].name];
// Setup session
self.mySession = [[MCSession alloc] initWithPeer:self.myPeerID];
self.mySession.delegate = self;
// Setup BrowserViewController
self.browserVC = [[MCBrowserViewController alloc] initWithServiceType:@"chat" session:self.mySession];
self.browserVC.delegate = self;
// Setup Advertiser
self.advertiser = [[MCAdvertiserAssistant alloc] initWithServiceType:@"chat" discoveryInfo:nil session:self.mySession];
[self.advertiser start];
}
我有两个子类,它们都是父类的子类。我尝试记录每个子类中连接的对等点的数量,都返回 0。此外,在记录时self.mySession
我得到这个:
mySession:<MCSession: 0x15d7aae0 MyPeerID = <MCPeerID: 0x15d7b360 DisplayName = Eric's iPhone> SecurityIdentity = (null) EncryptionPreference = Optional ConnectedPeers = (
) Delegate = <ChildViewController: 0x15d867f0>>
我从未将代表设置为孩子,但似乎认为 MCSession 代表已更改为孩子,而不是与父母呆在一起。每个子视图控制器都说它是委托,我认为为此每个子 VC 都应该说父是委托。我错过了什么?
另外:我正在使用情节提要。两个子 VC 都是嵌入在 NavigationController 中的控制拖动推送序列。导航控制器 > 父级 > 孩子 1 和孩子 2