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 – Multipeer Connectivity:无效的服务类型全部内容,希望文章能够帮你解决ios – Multipeer Connectivity:无效的服务类型所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。