Multipeer Connectivity: Invalid Service Type

I try to use the Multipeer Connectivity framework, but I get a failure when trying to instantiate MCNeaarbyServiceBrowser using serviceType.

Below is the code:

private func setUpSession() { self.session = MCSession(peer: self.peerId); self.session!.delegate = self; self.browser = MCNearbyServiceBrowser(peer: self.peerId, serviceType: "stc-classroom-vik"); self.browser!.delegate = self; self.advertiser = MCNearbyServiceAdvertiser(peer: self.peerId, discoveryInfo: nil, serviceType: "stc-classroom-vik"); self.advertiser!.delegate = self; } 

and this is the error / error I get:

 2014-08-15 12:24:42.689 Xavier[614:254319] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid serviceType passed to MCNearbyServiceBrowser' 

I would really appreciate any help.

+7
ios ios8 swift multipeer-connectivity
source share
3 answers

I believe that you are allowed to have only one hyphen in your serviceType parameter serviceType , and that should be 15 characters or less. You have two hyphens and 17 characters.

From the comments for MCNearbyServiceBrowser() :

The serviceType parameter is a short text string used to describe the network protocol of the application. It must be in the same format as the Bonjour Service Type: up to 15 characters and valid characters include ASCII lowercase letters, numbers, and hyphens. Short name that differs from unrelated services; for For example, a text chat application made by ABC may use the service type β€œA-txtchat”.

+17
source share

The length of your type of service is more than 15 characters and contains 2 hyphens.

I suggest you write a small function to check the serviceType string format for security.

+1
source share

The above answers are true in that the Bonjour service type can only contain 15 characters.

However, there is no β€œone hyphen” limit. The wording of the Bonjour specification is to describe the characters allowed in serviceType.

"stc-class-vik" is a valid type of serviceType

+1
source share

All Articles