【问题标题】:How to search and connect nearby bluetooth device classic (Not BLE) on iOS?如何在 iOS 上搜索和连接附近的经典蓝牙设备(非 BLE)?
【发布时间】:2017-02-08 09:30:26
【问题描述】:
我需要通过蓝牙设备搜索附近的经典蓝牙(蓝牙 2.1 或更高版本)。我搜索了很多,但只有关于 BLE 的库和讨论,任何指导都会对我有很大帮助。
【问题讨论】:
标签:
ios
objective-c
swift
bluetooth
core-bluetooth
【解决方案1】:
据我所知,除非您不手动配对和连接它们,否则您无法找到它们。为了发现已经配对和连接的,我使用这个:
import AVFoundation
func example() {
let session = AVAudioSession.sharedInstance()
do {
try session.setCategory(AVAudioSessionCategoryPlayAndRecord, with: AVAudioSessionCategoryOptions.allowBluetooth)
if let inputs = session.availableInputs { ... } //should contain bluetooth devices aswell
}
catch { print("Failed to set category") }
}
`