【问题标题】:How to fetch properties or name of paired two or more Bluetooth keyboard( keypad)如何获取配对的两个或多个蓝牙键盘(键盘)的属性或名称
【发布时间】:2020-06-02 12:14:18
【问题描述】:

如何获取配对的两个或多个蓝牙键盘(贝尔金键盘..)的属性或名称

我正在创建一个简单的测试项目,其中只有标签存在。两个蓝牙键盘(贝尔金键盘)连接到 iPad。我想找到这些设备的每个设备名称或任何属性或任何唯一路径,我可以在按键盘上的任何键时显示其名称。我想查找输入来自哪个设备。我尝试使用核心蓝牙,但它只显示外围设备没有显示我的蓝牙键盘名称。我也搜索 IOBluetooth,但它适用于 macOS。我需要在 iOS swift 中使用它。请帮助我。

试过这种方式...

//使用外部附件

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


}

【问题讨论】:

  • 我们可以得到的设备名称“peripheral.name”(使用CoreBluetooth)
  • @flowGlen 我尝试使用核心蓝牙(peripheral.name),但它只看到接近传感器、心率监视器和健身设备等外围设备名称,没有找到蓝牙密码键盘或蓝牙键盘名称(斯威夫特 iOS)
  • 请尝试实现然后检查广告数据 func centralManager(CBCentralManager, didDiscover: CBPeripheral, AdvertisementData: [String : Any], rssi: NSNumber) 还要检查下面的链接是否可以帮助你developer.apple.com/documentation/corebluetooth/…跨度>
  • @Manoj 我尝试使用 didDiscover 函数实现并实现,但它只显示其他外围设备而不是蓝牙键盘。我也尝试过使用特定的键盘输入 UUID,但它不起作用。有没有其他方法可以在 iOS swift 中找出外部蓝牙键盘名称或其独特属性?

标签: ios swift bluetooth ios-bluetooth numeric-keypad


【解决方案1】:

您可以使用EAAccessoryManager.shared().connectedAccessories 获取已连接的设备。

检查返回的EAAccessory是否有你需要的东西

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

【讨论】:

  • EAAccessory 管理器不工作。两个贝尔金键盘设备连接到 iPad,我实现了 EAAccessoryManager.shared().connectedAccessories,还尝试使用 showBluetoothAccessoryPickerWithNameFilter(),但它显​​示 null/()。还有其他方法可以找到蓝牙键盘或贝尔金键盘设备吗?
  • 我没有 BLE 键盘。但我可以为你试一次,明天就可以拿到代码。到那时你可以分享你正在使用的代码
  • 我编辑问题并添加外部配件代码..外部设备已连接到 iPad 但显示 0。请检查
猜你喜欢
  • 2019-06-11
  • 1970-01-01
  • 1970-01-01
  • 2011-05-14
  • 2021-09-27
  • 2011-12-17
  • 2017-05-09
  • 1970-01-01
  • 2023-02-13
相关资源
最近更新 更多