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.
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".
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With