ios – Multipeer Connectivity:无效的服务类型

我正在尝试使用Multipeer Connectivity框架,但在尝试使用serviceType实例化MCNeaarbyServiceBrowser时遇到了崩溃.

以下是代码:

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;
}

这是我得到的崩溃/错误:

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

我真的很感激任何帮助.

解决方法

我相信你只允许在你的serviceType参数字符串中使用一个连字符,并且它必须是15个字符或更少.你的有两个连字符和17个字符.

从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”.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...