【问题标题】:iOS - Swift Bluetooth - does not discover Android deviceiOS - Swift 蓝牙 - 未发现 Android 设备
【发布时间】:2018-03-06 01:47:06
【问题描述】:

我正在尝试用 Swift 编写一个发现 Android 手机(像素 2)的应用程序。但是,它没有显示在结果中。但是,我可以在 iphone 的常规蓝牙设置中找到像素(它是 iphone 8)。

我发现安卓手机的代码:

override func viewDidLoad() {
    super.viewDidLoad()
    centralManager = CBCentralManager(delegate: self, queue: nil)

}

func centralManagerDidUpdateState(_ central: CBCentralManager) {
    if (central.state == .poweredOn) {
        print("Powered on, starting scan")
        self.centralManager?.scanForPeripherals(withServices: nil, options: nil)
    } else {
        print("BT not powered on")
    }
}

func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
    print(peripheral)
}

它显示了其他 BT 设备,但没有显示 Android 手机。为了以防万一,我还编写了一个 Android 应用程序来明确启用 BT 可发现性。但仍然没有出现。

【问题讨论】:

  • 您的 Android 设备需要宣传 BLE GATT 服务才能使用您显示的代码进行发现。
  • @Paulw11 我要改变什么,才能在启用 BT 时发现它?
  • 您无法从 iOS 应用中发现旧版蓝牙设备。您只能发现 BLE GATT 服务。

标签: swift bluetooth core-bluetooth


【解决方案1】:

正如@Paulw11 所提到的,我必须创建一个 BLE GATT 服务来检测它。

看看这个例子:https://github.com/androidthings/sample-bluetooth-le-gattserver如果你以这种方式实现 Android 应用,iOS 应用就会发现该服务。

【讨论】:

    猜你喜欢
    • 2017-03-17
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-27
    • 1970-01-01
    相关资源
    最近更新 更多