我的设置是:我一次运行在0到8个设备之间,可以随时添加或删除设备。
我想使用iOS 7多点框架来连接它们。我有一个控制的环境,我可以启动1-7设备在广告模式,然后启动一个浏览器模式,他们都链接。
我不确定的是,当我启动设备时,我应该如何知道设备是否需要处于广告或浏览器模式?我试着在X秒内默认广告商模式,然后切换到浏览器,问题是所有设备都可能同时启动,同时关闭广告模式。
我也考虑过在广告商和浏览器模式下运行设备,但最初的问题是设备发现了自己。此外,我相信我有更少的设备连接到这种方式。
我肯定有一个推荐的方式来设置这个,但我一直找不到任何东西不假设有一个设置浏览器和广告商,有谁对此有建议?
发布于 2014-07-23 20:43:24
做所有的设备,无论是广告商还是浏览器,都很容易,这是一种正常的行为(我确信文档中提到了这一点,我稍后会搜索并添加链接)。
我发现自己的设备没有问题,也许您正在为同一个设备创建两个对等I?
您可能想检查一下这个的PLPartyTime的实现。它只是有几个简单的检查,看看它是否需要连接/接受连接。
广告代表
- (void)advertiser:(MCNearbyServiceAdvertiser *)advertiser
didReceiveInvitationFromPeer:(MCPeerID *)peerID
withContext:(NSData *)context
invitationHandler:(void(^)(BOOL accept, MCSession *session))invitationHandler
{
// Only accept invitations with IDs lower than the current host
// If both people accept invitations, then connections are lost
// However, this should always be the case since we only send invites in one direction
if ([peerID.displayName compare:self.peerID.displayName] == NSOrderedDescending)
{
invitationHandler(YES, self.session);
}
}浏览器代表
- (void)browser:(MCNearbyServiceBrowser *)browser foundPeer:(MCPeerID *)peerID withDiscoveryInfo:(NSDictionary *)info
{
// Whenever we find a peer, let's just send them an invitation
// But only send invites one way
// TODO: What if display names are the same?
// TODO: Make timeout configurable
if ([peerID.displayName compare:self.peerID.displayName] == NSOrderedAscending)
{
NSLog(@"Sending invite: Self: %@", self.peerID.displayName);
[browser invitePeer:peerID
toSession:self.session
withContext:nil
timeout:10];
}
}https://stackoverflow.com/questions/24920222
复制相似问题