【发布时间】:2019-05-11 10:58:00
【问题描述】:
我正在编写一个小型点对点蓝牙聊天应用程序。 我目前正在做的是:
let thread = Thread(block: { [weak self] in
guard let `self` = self else { return }
self.channel.inputStream.delegate = self
self.channel.inputStream.schedule(in: .current, forMode: .defaultRunLoopMode)
self.channel.inputStream.open()
self.channel.outputStream.delegate = self
self.channel.outputStream.schedule(in: .current, forMode: .defaultRunLoopMode)
self.channel.outputStream.open()
RunLoop.current.run()
})
thread.start()
self.channel 是 CBL2CAPChannel
我目前面临的问题是它会为每对通道生成新线程,最终导致线程过多。
在这种情况下设置CBL2CAPChannels 的正确方法是什么? Apple 的文档为此使用了主线程,这是出乎意料的,并且在连接很多时可能会导致问题。
【问题讨论】:
标签: ios bluetooth core-bluetooth nsstream l2cap