附近设备的iOS蓝牙mac地址

问题描述 投票:0回答:1

我想使用bluetooh获取附近设备的mac地址那就是我想要的格式。

FE:4F:AD:37:67:5D

我在委托人内部具有完全不同的mac地址格式

5962C58F-BAD1-65D4-DCAC-06BBB06307C6

这些是我正在使用的代表

CBCentralManagerDelegate

func centralManager(_ Central:CBCentralManager,didDiscover外设:CBPeripheral,advertisingData:[String:任意],rssi RSSI:NSNumber)

这是我的代码

  func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
            if(!peripherals.contains(peripheral)) {
                peripherals.append(peripheral)
            }

            let identifier = "\(peripheral.identifier)"
            if let data = identifier.data(using: .utf8) {
                let mac_address = data.hexEncodedString().uppercased()
                let macAddress = mac_address.separate(every: 2, with: ":")
                if let name = peripheral.name {
                    print("\(name) \n\(peripheral.identifier)\nMAC_ADDRESS: \(macAddress)")
                }

            }
        }


        func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) {
            mainPeripheral = nil
            print("Disconnected" + peripheral.name!)
        }


        func centralManagerDidUpdateState(_ central: CBCentralManager) {
            print(central.state)
            switch central.state {
            case .unknown:
                print("unknown")
            case .resetting:
                print("resetting")
            case .unsupported:
                print("unsupported")
            case .unauthorized:
                print("unauthorized")
            case .poweredOff:
                print("poweredOff")
                UIView.animate(withDuration: 0.7) {
                    self.lblBluetoothAlert.alpha = 1.0
                }
                stopScanForBLEDevices()
            case .poweredOn:
                UIView.animate(withDuration: 0.7) {
                    self.lblBluetoothAlert.alpha = 0.0
                }
                print("poweredOn")
                scanBLEDevices()
            default:
                print("default")
            }
        }
swift xcode core-bluetooth mac-address
1个回答
0
投票

Core蓝牙不提供对外围MAC地址的任何访问。

为了达到您在注释中概述的要求,即根据来自后端数据库的数据识别外围设备,您将需要您的外围设备也通过以下方式公开其标识符(可能是其MAC地址,可能还有一些其他唯一标识符)一个特征。然后,您的应用程序可以连接到目标外设并询问特性。

© www.soinside.com 2019 - 2024. All rights reserved.