Post not yet marked as solved
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)
Post not yet marked as solved
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)?
Post not yet marked as solved
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.
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?
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
Post not yet marked as solved
I am getting dozens of crash reports for our app running on iOS 14. The crash log (please see attached) indicates the crash on Thread 0. I am not able to reproduce the crash.
CrashLog
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.
Post not yet marked as solved
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
Post not yet marked as solved
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.
Post not yet marked as solved
[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] <Warning>: 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?
Post not yet marked as solved
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.
Post not yet marked as solved
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
{
		[NSTimer scheduledTimerWithTimeInterval:0.5f
																		 target:self
																	 selector:@selector(switchBrowsing)
																	 userInfo:nil
																		repeats:NO];
		[self stopBrowsingForPeers];
		[self startBrowsingForPeers];
}
Environment: iPhone XR(MT0G2J/A) running iOS 14.0 beta6
iPad 6th(MR7G2J/A) running iPadOS 14.0 beta7
Thanks.
Post not yet marked as solved
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<MultipeerConnectivityBrowserView>) -> 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<MultipeerConnectivityBrowserView>) {
}
}
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 {
		private static var internalInstance: MultipeerConnectivityService? = nil
		
		let serviceType = "sn-dueladviser"
		let peerID = MCPeerID(displayName: UIDevice.current.name)
		
		var session: MCSession?
		var advertiserAssistant: MCAdvertiserAssistant?
		
		static func instance() -> MultipeerConnectivityService {
				if let instance = internalInstance {
						return instance
				}
				
				internalInstance = MultipeerConnectivityService()
				return internalInstance!
		}
		
		private override init() {
				super.init()
				
				session = MCSession(peer: peerID, securityIdentity: nil, encryptionPreference: .required)
				session?.delegate = self
		}
		
		func startHosting() {
				guard let session = session else { return }
				advertiserAssistant = MCAdvertiserAssistant(serviceType: serviceType, discoveryInfo: nil, session: session)
				advertiserAssistant?.delegate = self
				
				advertiserAssistant?.start()
		}
		
		func session(_ session: MCSession, didReceive stream: InputStream, withName streamName: String, fromPeer peerID: MCPeerID) {
				
		}
		
		func session(_ session: MCSession, didStartReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, with progress: Progress) {
				
		}
		
		func session(_ session: MCSession, didFinishReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, at localURL: URL?, withError error: Error?) {
				
		}
		
		func browserViewControllerDidFinish(_ browserViewController: MCBrowserViewController) {
				browserViewController.dismiss(animated: true, completion: { })
		}
		
		func browserViewControllerWasCancelled(_ browserViewController: MCBrowserViewController) {
				browserViewController.dismiss(animated: true, completion: { })
		}
		
		func session(_ session: MCSession, peer peerID: MCPeerID, didChange state: MCSessionState) {
				switch state {
				case .connected:
						print("Connected: \(peerID.displayName)")
				case .connecting:
						print("Connecting: \(peerID.displayName)")
				case .notConnected:
						print("Not Connected: \(peerID.displayName)")
						
				@unknown default:
						print("Unknown state received: \(peerID.displayName)")
				}
		}
		
		func session(_ session: MCSession, didReceive data: Data, fromPeer peerID: MCPeerID) {
				//todo: Receive data
		}
}
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.