Nick Red
Nick Red

Reputation: 396

Multipeer Connectivity Connecting / Managing Peers Manually

I am trying to figure out what the NSData object is to connect to a peer manually. I can't find it in the apple documentation, all it says is that it needs the connection data object from the peer but I cant find where I get that from. Here is the Apple Doc

I want to use this

 func connectPeer(_ peerID: MCPeerID!, withNearbyConnectionData data: NSData!)

I am using this method when a peer disconnects. For some reason when a peer disconnects I can still send and receive information from it so I want to force the reconnection with this method.

Thanks for any help

Upvotes: 2

Views: 1080

Answers (2)

dev gr
dev gr

Reputation: 2431

If you really want to know about data which is passed to peers to establish connection, I sugest you should go through this documet: truth about multipeer connectivity framework

Upvotes: 0

ChrisH
ChrisH

Reputation: 4558

The NSData object you are looking for is part of this function's completion block:

func nearbyConnectionDataForPeer(_ peerID: MCPeerID!,
       withCompletionHandler completionHandler: ((NSData!,
                                      NSError!) -> Void)!)

It's not clear from the documentation, but I suspect your own discovery code would pass your locally created MCPeerID object to other discovered devices during the initial connection phase. Then you'd use the discovered peer's MCPeerID object in the above function, and finally call the connectPeer function with the data you get back.

I'd be interested to hear if you ever get this working!

Upvotes: 2

Related Questions