I'am working on a peer to peer chat application in iOS using multipeer connectivity framework, i have setup both advertiser and browser in my app. Here is the advertiser and initialisation code:
_myDisplayname = [[UIDevice currentDevice] name]; _mypeer =[[MCPeerID alloc]initWithDisplayName:_myDisplayname];
_mySession = [[MCSession alloc]initWithPeer:_mypeer securityIdentity:nil encryptionPreference:MCEncryptionRequired];
self.mySession.delegate = self;
_assistant = [[MCAdvertiserAssistant alloc]initWithServiceType:serviceType discoveryInfo:nil session:_mySession]; [_assistant start]; _nearbyBrowser = [[MCNearbyServiceBrowser alloc]initWithPeer:_mypeer serviceType:serviceType];
self.advertiser = [[MCNearbyServiceAdvertiser alloc]initWithPeer:self.mypeer discoveryInfo:nil serviceType:@"blue-chat"];
-I have advertised the service using MCAdvertiserAssistant in viewDidLoad and browsing code is as follows :
MCBrowserViewController *browser = [[MCBrowserViewController alloc]initWithBrowser:self.nearbyBrowser session:self.mySession];
browser.delegate =self;
[self presentViewController:browser animated:YES completion:nil];
- I have used the same session object for both advertiser and browser, When launched fresh on two iOS devices (iPhone 4s and iPhone 6 ) ,the two devices get connected and chat works but after some time of chatting the the peer is disconnected, also sometimes within a minute of making connection, the peers get disconnected. Any help is appreciated. Thanks!!