0

How to fetch properties or name of paired two or more BlueTooth keyboards (Belkin keypad..)

I am creating a simple test project in that only label is present. Two Bluetooth keyboards (Belkin keypad)is connected to iPad. I want to find each device name or any properties or any unique path of those devices that I can show its name when pressing any key from pin pad. I want to find input come from which device. I tried using core Bluetooth but it only shows peripherals not showing my Bluetooth keypad name.I also search IOBluetooth but it is for macOS. I require to use it in iOS swift. kindly help me .

tried this way...

//Using External accessory

import UIKit

import ExternalAccessory

class ViewController: UIViewController 

{

@IBOutlet weak var tableView: UITableView!

var manager = EAAccessoryManager.shared()

override func viewDidLoad() {
     super.viewDidLoad()

     let a = manager.connectedAccessories.count
     print(a)// print 0

NotificationCenter.default.addObserver(self, selector: #selector(deviceConnected), name: NSNotification.Name.EAAccessoryDidConnect, object: nil)

}

@objc func deviceConnected(notification: NSNotification) 

{

 if let acc = notification.userInfo![EAAccessoryKey] 
{
showAccessoryInfo(accessory: acc as! EAAccessory)
print("Connected:", acc)
      }
   tableView.reloadData()
  }

 func showAccessoryInfo(accessory: EAAccessory) 
   {
 print("title\(accessory.manufacturer) and name :\(accessory.name) and message \(accessory.description)")
    }


 func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
    }

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return manager.connectedAccessories.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
         print("10")
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
      let acc = manager.connectedAccessories[indexPath.row]
              cell.textLabel?.text = "\(acc.manufacturer) \(acc.name)"
              cell.detailTextLabel?.text = "\(acc.modelNumber) \(acc.serialNumber)\n fr:\(acc.firmwareRevision) hr: \(acc.hardwareRevision)"
         print("11")
      return cell
}
func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
      let acc = manager.connectedAccessories[indexPath.row]
    showAccessoryInfo(accessory: acc)
         print("12")
}


}
Pooja ios
  • 1
  • 2
  • the name of the device we can get so "peripheral.name" (use CoreBluetooth) – flowGlen Feb 18 '20 at 14:05
  • @flowGlen I tried using core bluetooth (peripheral.name) but it only see peripheral name like proximity sensors, heart rate monitors, and fitness devices didn't find bluetooth pin-pad or bluetooth keyboard name (Swift iOS) – Pooja ios Feb 19 '20 at 03:29
  • please try implementing and then checking the advertisementData func centralManager(CBCentralManager, didDiscover: CBPeripheral, advertisementData: [String : Any], rssi: NSNumber) Also check if below link can help you https://developer.apple.com/documentation/corebluetooth/cbcentralmanagerdelegate/advertisement_data_retrieval_keys – Manoj Feb 19 '20 at 10:01
  • @Manoj I tried and implementing with didDiscover func but it shows only other peripherals not bluetooth keyboard. I also tried with specific keyboard input UUID but its not working. Is there any another way to find out external bluetooth keyboard name or its unique properties in iOS swift ? – Pooja ios Feb 21 '20 at 05:17

1 Answers1

1

You can use EAAccessoryManager.shared().connectedAccessories for getting connected devices.

Check if the returned EAAccessory has what you need

https://developer.apple.com/library/prerelease/ios/documentation/ExternalAccessory/Reference/EAAccessoryManager_class/index.html#//apple_ref/occ/instp/EAAccessoryManager/connectedAccessories

Manoj
  • 1,019
  • 9
  • 17
  • EAAccessory Manager not working. two belkin keypad devices are connected to iPad and I implemented EAAccessoryManager.shared().connectedAccessories and also tried to used showBluetoothAccessoryPickerWithNameFilter() but it shows null/(). Any other way to find Bluetooth keyboard or belkin keypad device ? – Pooja ios Feb 24 '20 at 12:09
  • I do not own a BLE keyboard. But I can try once for you and get with the code tomorrow. Till then can you share the code which you are using – Manoj Feb 24 '20 at 14:01
  • I edit the question and add a code of external accessories..In that external Device is connected to iPad but showing 0. Please Check – Pooja ios Feb 26 '20 at 03:15