Multipeer Connectivity

RSS for tag

Support peer-to-peer connectivity and the discovery of nearby devices using MultipeerConnectivity.

Multipeer Connectivity Documentation

Posts under Multipeer Connectivity tag

33 Posts
Sort by:
Post not yet marked as solved
1 Replies
327 Views
I get the following error when configuring MCBrowserViewController to look for nearby peers. And this is despite appending the required info in info.plist namely, [MCNearbyServiceBrowser] NSNetServiceBrowser did not search with error dict [{     NSNetServicesErrorCode = "-72008";     NSNetServicesErrorDomain = 10; }]. NSLocalNetworkUsageDescription <string>Need permission to discover and connect to My Service running on peer iOS device</string> NSBonjourServices <array> <string>_my-server._tcp</string> <string>_my-server._udp</string> </array> Here is my code: let browser = MCBrowserViewController(serviceType: "my-server", session: session)             browser.delegate = self             browser.minimumNumberOfPeers = kMCSessionMinimumNumberOfPeers             browser.maximumNumberOfPeers = 1             self.present(browser, animated: true, completion: nil)
Posted
by
Post not yet marked as solved
0 Replies
475 Views
After upgrading to IOS15, I'm getting disconnects using multipeer connect when the network is not in use. Sending manual keep alive messages every second seems to prevent this from happening. This only occurs when devices are connected directly and not via wifi infrastructure Has the underlying implementation of MultipeerConnect changed in IOS15 (ie no longer NSNetService)?
Posted
by
Post not yet marked as solved
1 Replies
326 Views
Hey I wanna make an app where I am able to have users create a room and invite other users using some invite link or room code I was wondering if anyone can give me pointers on how to do this? An example of my UI is below. Creating the UI shouldnt be too hard its just trying to find how to group users together.
Posted
by
Post marked as solved
3 Replies
393 Views
Is there a way to increase the range of MultipeerConnectivity WIFI? I have read a few posts answered by @eskimo at Apple which states that a range over 5 meters is probably to long. "Given the way that Apple’s peer-to-peer Wi-Fi is currently implemented, there’s a tradeoff between range and connection setup reliability. The longer the range, the harder it is for the system to set up the connection. To help with this Apple uses very low transmission power for peer-to-peer Wi-Fi. This reduces the effective range but makes connection setup much more reliable. So the range you’re testing at, 5 metres, is actually quite long range for peer-to-peer Wi-Fi." I am trying to write a rear view mirror app for my 7 meter long Motorhome using MultipeerConnectivity and although I can get an iPhone at the back of the motorhome to transmit video to an iPhone at the front of the motorhome attached to the rear view mirror which displayed the live video, the connection gets dropped quite regularly. Is there a way to boost the signal by another 50% once I have made the connection which I can initially do with the iPhones in close proximity?
Posted
by
Post marked as solved
2 Replies
444 Views
Hi, I'm trying to use the Multipeer Connectivity framework in my latest app to create a mesh network between many devices (20+). I only plan to have each device connected to at most 4 other devices to avoid the limitations of the MC framework. However, when testing it out I found that when connecting multiple peers together, the MCSessions seemed to sync up. I.e. when I had device 1 connect to device 2, and then device 1 connect to device 3, automatically device 2 would connect to device 3. Is there any way to prevent these automatic connections from forming between devices? I am using swift 5 / iOS 14 Thanks
Posted
by
Post marked as solved
1 Replies
720 Views
Hi, I've been trying to make an app that can connect to more than one UWB source at a time. I've three iPhone 12 Pro and I am using NearbyInteraction to retrieve the distance and direction from one iPhone to the other. I've used MultipeerConnectivity to share the discovery tokens from all devices. My code at the moment can perfectly handle two devices sharing their distance and direction, but at soon as I connect the third phone, all sharing stops. I am wondering if I am doing something wrong or if there is a limitation on Apple side to prevent devices from retrieving the distance and direction from more than one source at a time. I am not giving too much detail about my implementation yet, but don't hesitate to ask questions about it. Thanks in advance for your help.
Posted
by
Post not yet marked as solved
1 Replies
410 Views
Hi I have a peer to peer VoIP application supposed to work without Internet access. Everything works fine except incoming calls reception while in background. I know that the recommended approach for VoIP applications is to use push notifications, but this is not an option for this application. Are there other options to receive incoming calls while in background ? thank you Bogdan
Posted
by
Post not yet marked as solved
6 Replies
1.8k Views
NetServiceBrowser service always fails on iPhone if we create build from xcode 12. // We are using following line in to start searching for sevices available on network //         self.serviceBrowser.searchForServices(ofType: "_http._tcp.", inDomain: "local.")    It return following error dicitonary : ["NSNetServicesErrorCode": -72008, "NSNetServicesErrorDomain": 10] I did not find -72008 in error codes for NSNetServicesErrorDomain. It works as exepcted with previous vesions of Xcode. With Xcode 12 it works only on Simulator.
Posted
by
Post not yet marked as solved
4 Replies
1k Views
[Match] cannot set connecting state for players: ( "..." ), as there is no inviteDelegate set yet. The state might directly change to Ready when we set the inviteDelegate later and call sendQueuedStatesAndPackets. We are setting the match.delegate to our implementation of GKMatchDelegate and GKMatchmakerViewControllerDelegate. It also prints a warning later: [Developer] &lt;Warning&gt;: need to implement one of the following methods in GKMatchDelegate: match:didReceiveData:forRecipient:fromRemotePlayer:, match:didReceiveData:fromRemotePlayer: However we are certainly implementing that func: public func match(_ match: GKMatch, didReceive data: Data, forRecipient recipient: GKPlayer, fromRemotePlayer player: GKPlayer) { print("Data received from player..."); } Any ideas?
Posted
by
Post not yet marked as solved
9 Replies
2.2k Views
Latest beta for Big Sur, Macbook Air 2020 connects to house wifi without problem but will not locate mobile phone for hotspot connection. Anyone know a work around or have similar issue.
Posted
by
Post not yet marked as solved
2 Replies
744 Views
Hi, I have a problem that the app crashes when using MCNearbyServiceBrowser startBrowsingForPeers on iOS14. It occurs in the process of repeating startBrowsingForPeers and stopBrowsingForPeers of MCNearbyServiceBrowser every few seconds. This does not occur on iOS 13 and below. For example, it occurs when you call the following method. (void)switchBrowsing { &#9;&#9;[NSTimer scheduledTimerWithTimeInterval:0.5f &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; target:self &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; selector:@selector(switchBrowsing) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; userInfo:nil &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;repeats:NO]; &#9;&#9;[self stopBrowsingForPeers]; &#9;&#9;[self startBrowsingForPeers]; } Environment: iPhone XR(MT0G2J/A) running iOS 14.0 beta6 iPad 6th(MR7G2J/A) running iPadOS 14.0 beta7 Thanks.
Posted
by
Post not yet marked as solved
4 Replies
1.3k Views
I tried now two different approaches (MCAdvertiserAssistant / MCBrowserViewController and MCNearbyServiceAdvertiser / MCNearbyServiceBrowser) to implement this in my first Swift app but always got the result that it stays at "Connecting" for a few seconds and than just declines the request. In a video from Hacking with Swift there was a popup if the connection should be accepted - this never comes up on my devices. So maybe this is the error already? As for the browser part, I use this ViewController wrapper to make it available: import MultipeerConnectivity import SwiftUI struct MultipeerConnectivityBrowserView: UIViewControllerRepresentable {   func makeUIViewController(context: UIViewControllerRepresentableContext&lt;MultipeerConnectivityBrowserView&gt;) -> MCBrowserViewController {     let service = MultipeerConnectivityService.instance()     guard let session = service.session else {       print("Failed to load MCSession for Browser")       return MCBrowserViewController()     }           let viewController = MCBrowserViewController(serviceType: service.serviceType, session: session)     viewController.delegate = service           return viewController   }   func updateUIViewController(_ uiViewController: MCBrowserViewController, context: UIViewControllerRepresentableContext&lt;MultipeerConnectivityBrowserView&gt;) {   } } struct MultipeerConnectivityBrowserView_Previews: PreviewProvider {   static var previews: some View {     MultipeerConnectivityBrowserView()   } } I can see my 2nd device in the upcoming dialog but when I click on it, as described above, it just hangs at "Connecting" until it, as it seems to me, timed out. This is currently the main implementation for the MC in my app: import MultipeerConnectivity class MultipeerConnectivityService: NSObject, MCSessionDelegate, MCBrowserViewControllerDelegate, MCAdvertiserAssistantDelegate { &#9;&#9;private static var internalInstance: MultipeerConnectivityService? = nil &#9;&#9; &#9;&#9;let serviceType = "sn-dueladviser" &#9;&#9;let peerID = MCPeerID(displayName: UIDevice.current.name) &#9;&#9; &#9;&#9;var session: MCSession? &#9;&#9;var advertiserAssistant: MCAdvertiserAssistant? &#9;&#9; &#9;&#9;static func instance() -> MultipeerConnectivityService { &#9;&#9;&#9;&#9;if let instance = internalInstance { &#9;&#9;&#9;&#9;&#9;&#9;return instance &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;internalInstance = MultipeerConnectivityService() &#9;&#9;&#9;&#9;return internalInstance! &#9;&#9;} &#9;&#9; &#9;&#9;private override init() { &#9;&#9;&#9;&#9;super.init() &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;session = MCSession(peer: peerID, securityIdentity: nil, encryptionPreference: .required) &#9;&#9;&#9;&#9;session?.delegate = self &#9;&#9;} &#9;&#9; &#9;&#9;func startHosting() { &#9;&#9;&#9;&#9;guard let session = session else { return } &#9;&#9;&#9;&#9;advertiserAssistant = MCAdvertiserAssistant(serviceType: serviceType, discoveryInfo: nil, session: session) &#9;&#9;&#9;&#9;advertiserAssistant?.delegate = self &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;advertiserAssistant?.start() &#9;&#9;} &#9;&#9; &#9;&#9;func session(_ session: MCSession, didReceive stream: InputStream, withName streamName: String, fromPeer peerID: MCPeerID) { &#9;&#9;&#9;&#9; &#9;&#9;} &#9;&#9; &#9;&#9;func session(_ session: MCSession, didStartReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, with progress: Progress) { &#9;&#9;&#9;&#9; &#9;&#9;} &#9;&#9; &#9;&#9;func session(_ session: MCSession, didFinishReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, at localURL: URL?, withError error: Error?) { &#9;&#9;&#9;&#9; &#9;&#9;} &#9;&#9; &#9;&#9;func browserViewControllerDidFinish(_ browserViewController: MCBrowserViewController) { &#9;&#9;&#9;&#9;browserViewController.dismiss(animated: true, completion: { }) &#9;&#9;} &#9;&#9; &#9;&#9;func browserViewControllerWasCancelled(_ browserViewController: MCBrowserViewController) { &#9;&#9;&#9;&#9;browserViewController.dismiss(animated: true, completion: { }) &#9;&#9;} &#9;&#9; &#9;&#9;func session(_ session: MCSession, peer peerID: MCPeerID, didChange state: MCSessionState) { &#9;&#9;&#9;&#9;switch state { &#9;&#9;&#9;&#9;case .connected: &#9;&#9;&#9;&#9;&#9;&#9;print("Connected: \(peerID.displayName)") &#9;&#9;&#9;&#9;case .connecting: &#9;&#9;&#9;&#9;&#9;&#9;print("Connecting: \(peerID.displayName)") &#9;&#9;&#9;&#9;case .notConnected: &#9;&#9;&#9;&#9;&#9;&#9;print("Not Connected: \(peerID.displayName)") &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;@unknown default: &#9;&#9;&#9;&#9;&#9;&#9;print("Unknown state received: \(peerID.displayName)") &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9; &#9;&#9;func session(_ session: MCSession, didReceive data: Data, fromPeer peerID: MCPeerID) { &#9;&#9;&#9;&#9;//todo: Receive data &#9;&#9;} } I tried to add NSLocalNetworkUsageDescription and NSBonjourServices without any change (even if both are not mentioned in any guides except the official documentation). Sadly it didn't change anything + it seems like my XCode does not know these keys or at least do not replace the key name with another text like it did with other keys like camera permission.
Posted
by