I have a simple chat application which uses Multipeer connectivity to send text back and forth.
I am using the MCSessionDelegate
.
-(void)advertiseSelf:(BOOL)shouldAdvertise{
if (shouldAdvertise) {
_advertiser = [[MCAdvertiserAssistant alloc] initWithServiceType:@"messagingapp"
discoveryInfo:nil
session:_session];
[_advertiser start];
}
else{
[_advertiser stop];
_advertiser = nil;
}
}
When the user connects, I call the below:
-(void)hideSelf{
[self.swVisible setOn:NO];
[_appDelegate.mcManager advertiseSelf:_swVisible.isOn];
}
I want the app to stop advertising as the application is a One to One communication app.
The problem is, this results in MCSessionStateNotConnected
I have set the _browser.maximumNumberOfPeers
to 2
but I cannot see another way to hiding visibility whilst in session without causing the session connection to drop.
Please help Thanks
You should establish different sessions for each peer trying to connect to your host. By doing so, you would be able to deny the invitation without affecting other connected sessions.