我如何获取iOS Swift中蓝牙已打开的设备的名称

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

我想在蓝牙设备上获取所有信息。我正在使用SwiftyBluetooth。

import SwiftyBluetooth

SwiftyBluetooth.scanForPeripherals(withServiceUUIDs: nil, timeoutAfter: 15) { scanResult in
    switch scanResult {
    case .scanStarted:
        // The scan started meaning CBCentralManager scanForPeripherals(...) was called
        print("scan Started")
    case .scanResult(let peripheral, let advertisementData, let RSSI):

        // A peripheral was found, your closure may be called multiple time with a .ScanResult enum case.
        // You can save that peripheral for future use, or call some of its functions directly in this closure.
        print("::::\(peripheral)")
        self.peripheralArray.append(peripheral)
        print("\(advertisementData)")
        print("RSSI\(RSSI)")
    case .scanStopped(let error):
        print("error\(error)")
        // The scan stopped, an error is passed if the scan stopped unexpectedly
    }
}

此代码为我提供了Mi乐队和电视的名称,但无论如何也无法获得iPhone或Android手机的名称。

swift core-bluetooth
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.