senty
senty

Reputation: 12847

Multipeer Connectivity stores PeerID from previous sessions

func browser(browser: MCNearbyServiceBrowser!, foundPeer peerID: MCPeerID!, withDiscoveryInfo info: [NSObject : AnyObject]!) {

    println(peerID) 

}

When I use this line of code, I receive peerIDs from previous sessions first, and then it gives the new peerIDs from the current session. Where is this data stored? Is there any way that I can remove the stored ones; maybe initialising somehow at the View Controller? I just want to get the peerID from the current session.

This is the console log:

<MCPeerID: 0x15559080 DisplayName = iphone>
<MCPeerID: 0x156616e0 DisplayName = iphooneeee>
<MCPeerID: 0x1563da30 DisplayName = iphooneeee>

Upvotes: 1

Views: 565

Answers (2)

senty
senty

Reputation: 12847

I couldn't sort out the storing issue but I found a way around by creating en empty array, initiating it to empty everytime I click on the button (which sorted out in my case), and saving the peerID in the array.

 ~ ViewController {
foundPeers: MCPeerID = []

~ ViewDidLoad {
  foundPeers = []

}

 @IBAction var button~ {
   foundPeers = []
} 

// and
  func browser(browser: MCNearbyServiceBrowser!, foundPeer peerID: MCPeerID!, withDiscoveryInfo info: [NSObject : AnyObject]!) {

  foundPeers.append(peerID)

  foundPeers[foundPeers.count - 1].displayName
 }
}

Stored the data manually and

Upvotes: 0

bootchk
bootchk

Reputation: 2016

Just a guess... a session is a distributed object. The framework (the OS) stores data for a session distributed across all devices participating in the session. You might need to reboot all such devices to truly erase all data about the session. I can't say how the framework knows when to erase a session that is stale or expired. But for example, it could be keeping a session for a long time in case a device comes back in range.

Upvotes: 2

Related Questions