phoebus
phoebus

Reputation: 1329

iOS - Swift Bluetooth - does not discover Android device

I am trying to write an app in Swift that discovers a Android phone (pixel 2). However, it is not showing up in the results. I can however find the pixel in the regular bluetooth settings of the iphone (it's an iphone 8).

My code to discover the Android phone:

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)
}

It shows me other BT devices but not the Android phone. I also did write an Android app to explicitly enable BT discoverability just in case. But still not showing up.

Upvotes: 3

Views: 2271

Answers (1)

phoebus
phoebus

Reputation: 1329

As @Paulw11 has mentioned, I had to create a BLE GATT service to detect it.

Just look at this example here: https://github.com/androidthings/sample-bluetooth-le-gattserver If you implement the Android app in that way, the iOS app will discover the service.

Upvotes: 1

Related Questions