Error on Multipeer Connectivity after updating to Xcode 12 and iPadOS 14

Dear all,

I ask you for some help after receiving an error while I was executing the following piece of code.

Code Block
session = MCSession(peer: MCPeerID(displayName: UIDevice.current.name), securityIdentity: nil, encryptionPreference: .optional )
session?.delegate = self
assistant = MCAdvertiserAssistant(serviceType: "PlayWithEyes", discoveryInfo: nil, session: session!)
browser = MCBrowserViewController(serviceType: "PlayWithEyes", session: session! )
browser?.delegate = self
assistant!.start()
browser?.modalPresentationStyle = .formSheet
present(browser!, animated: true, completion: nil)


I received the following runtime error:


Exception NSException * "-[MCAdvertiserAssistant advertiser:didNotStartAdvertisingPeer:]: unrecognized selector sent to instance 0x280130ee0" 0x0000000282461e00

Has anyone of you some ideas?
The code works well on the simulator, but no in the physical device.

Thank you in advance,

Mirko Franco



Accepted Reply

I have just found a solution.
Given this code example:

Code Block
assistant = MCAdvertiserAssistant(serviceType: "service", discoveryInfo: nil, session: session!)
browser = MCBrowserViewController(serviceType: "service", session: session! )

It is sufficient to insert in the info.plist the following fields:

1) Privacy - Local Network Usage Description
2) Bonjour services with the following initialisation: _service._tcp and _service._udp



Replies

Is happening to me as well on iOS 14. Everything is fine with iOS 12/13.
Have you find any solution?
I have just found a solution.
Given this code example:

Code Block
assistant = MCAdvertiserAssistant(serviceType: "service", discoveryInfo: nil, session: session!)
browser = MCBrowserViewController(serviceType: "service", session: session! )

It is sufficient to insert in the info.plist the following fields:

1) Privacy - Local Network Usage Description
2) Bonjour services with the following initialisation: _service._tcp and _service._udp



still not working for me (iPhone 11 Pro Max)
@mirkofranco, thanks for the solution it worked for. The thing to note is make sure that serviceType: "service" and Bonjour services is initialised with values _service._tcp and _service._udp. The values are important and they need to be set accordingly.
I got it to work on iOS 14, but as @deepshah7 says you need to change the name of the "service" part of the Bonjour services value to the specific name of your serviceType. So if you have serviceType: "myCollabSession", the Bonjour services need to be _myCollabSession._tcp and _myCollabSession._udp