ios - 如何将 MacBook 变成具有 BLE 扫描服务的外围设备?
问题描述
我正在尝试将我的 MacBook 用作具有蓝牙扫描服务的外围设备,因此可以像这样使用它:
var manager:CBCentralManager?
manager?.scanForPeripherals(withServices: nil, options: nil)//the withServices will be replaced with custom service UUID
我尝试创建自己的自定义服务 UUID 并将其添加到 peripheralManager 中,如下所示:
var peripheralManager: CBPeripheralManager?
override func viewDidLoad() {
super.viewDidLoad()
createServiceUUID()
peripheralManager?.startAdvertising(["Test" : "Test"])
}
func createServiceUUID() {
let customServiceUUID = CBUUID(string: customServiceUUIDString)
let mutableService = CBMutableService(type: customServiceUUID, primary: true)
peripheralManager?.add(mutableService)
}
然后我尝试扫描我刚刚创建的 serviceUUID,但它没有显示:
manager?.scanForPeripherals(withServices: [CBUUID(string: customServiceUUIDString)], options: nil)
我觉得我可能错过了将我的 Mac 变成可以使用
scanForPeripherals(withServices:)
功能。关于如何实现这一点的任何想法?
解决方案
推荐阅读
- python - ValueError:字符串格式说明符中不允许“=”对齐。有时不工作
- c# - C# 中带有泛型的 void 任务
- web-scraping - 如何从bs4中的标签数组中获取字符串?
- sql - 如何在 Join 中获取 Laravel Eloquent Count 和 Case
- unity3d - MRTK 2.4 - ScrollingObjectCollection 不通过脚本更新
- c# - 带有抽象 Equals 方法的 C# 抽象记录
- composer-php - 作曲家安装自动加载失败
- python - 函数中的 Subprocess.call() 不会暂停调用该函数的脚本
- sql - 即使没有有损块,也会执行 Postgresql 重新检查
- javascript - 我怎样才能在反应原生的标题栏上获得这种模糊效果?