Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multipeer Connectivity: Invalid service type

I am trying to use the Multipeer Connectivity framework but I am getting a crash while trying to instantiate MCNearbyServiceBrowser with a serviceType called "stc-classroom-vik".

Here 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 crash/error I am getting:

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.

like image 955
Vik Singh Avatar asked Aug 15 '14 19:08

Vik Singh


3 Answers

I believe you're only allowed to have one hyphen in your serviceType parameter string, and it needs to be 15 characters or fewer. Yours has two hyphens and 17 characters.

From the comments for MCNearbyServiceBrowser():

The serviceType parameter is a short text string used to describe the app's networking protocol. It should be in the same format as a Bonjour service type: up to 15 characters long and valid characters include ASCII lowercase letters, numbers, and the hyphen. A short name that distinguishes itself from unrelated services is recommended; for example, a text chat app made by ABC company could use the service type "abc-txtchat".

like image 176
Nate Cook Avatar answered Nov 18 '22 09:11

Nate Cook


Your service type length is more than 15 characters long and containing 2 hyphens.

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

like image 30
thkeen Avatar answered Nov 18 '22 09:11

thkeen


The above answers are correct in that a Bonjour service type may only have 15 characters.

However, there is not a "one hyphen" limit. The wording of the Bonjour specification is to describe the characters which are permitted in the serviceType.

"stc-class-vik" is a valid serviceType

like image 1
Gilles Dignard Avatar answered Nov 18 '22 08:11

Gilles Dignard