Multipeer Connectivity Framework - Connectivity Issue

I have tried almost all the tutorials and Apple documents regarding Multipeer Connectivity. It is working but on some situations like If I manually call the session.disconnect() and then try to re-connect with the available peers, it has never gotten connected.


Also If I force quit the application, and try to connect with the device after re-launching the application, the framework fails to establish connection between devices.


What happens actually is, when I try re-connect the devices, the peer devices is being shown in my device. When I send an invite to the peer device, the MCSession state changes to CONNECTING and after few seconds, it is changed to NOT CONNECTED.


I have done the following to properly destroy the session, advertiser and broswer.


func applicationWillTerminate(_ application: UIApplication) {

/

mpcManager.reset()

print("\(mpcManager) Resetting MCManager")

mpcManager.advertiser = nil

mpcManager.browser = nil

mpcManager.session = nil

mpcManager = nil

}


But unfortunately, nothing works.


Kindly help me out this.

The mpcManager.reset() actually does the following.


browser?.stopBrowsingForPeers()

advertiser?.stopAdvertisingPeer()

session?.disconnect()

Multipeer Connectivity Framework - Connectivity Issue
 
 
Q