Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Swift 3.0中获取最近的蓝牙设备列表_Swift_Swift3_Bluetooth_Core Bluetooth_Cbcentralmanager - Fatal编程技术网

如何在Swift 3.0中获取最近的蓝牙设备列表

如何在Swift 3.0中获取最近的蓝牙设备列表,swift,swift3,bluetooth,core-bluetooth,cbcentralmanager,Swift,Swift3,Bluetooth,Core Bluetooth,Cbcentralmanager,我正在尝试使用框架获取最近的蓝牙,我导入框架并实现CBCentralManagerDelegate,cbperipheraldegate 这是我的密码: import CoreBluetooth centralManager = CBCentralManager(delegate: self, queue: nil) func centralManagerDidUpdateState(_ central: CBCentralManager) { gua

我正在尝试使用框架获取最近的蓝牙,我导入框架并实现
CBCentralManagerDelegate
cbperipheraldegate

这是我的密码:

import CoreBluetooth

        centralManager = CBCentralManager(delegate: self, queue: nil)

    func centralManagerDidUpdateState(_ central: CBCentralManager) {
        guard central.state  == .poweredOn else {
            return
        }
        scanDevice()
    }

    func scanDevice() {

        centralManager?.scanForPeripherals(
            withServices: [transferServiceUUID], options: [
                CBCentralManagerScanOptionAllowDuplicatesKey : NSNumber(value: true as Bool)
            ]
        )
    }
    func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {

        print("Discovered \(peripheral.name) at \(RSSI)")
        if discoveredPeripheral != peripheral {
            discoveredPeripheral = peripheral
            print("Connecting to peripheral \(peripheral)")
            centralManager?.connect(peripheral, options: nil)
        }
    }
    func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?) {
        print("Failed to connect to \(peripheral). (\(error!.localizedDescription))")

    }
    func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
        print("Peripheral Connected")

        // Stop scanning
        centralManager?.stopScan()
        print("Scanning stopped")

        // Clear the data that we may already have
        data.length = 0

        // Make sure we get the discovery callbacks
        peripheral.delegate = self

        // Search only for services that match our UUID
        peripheral.discoverServices([transferServiceUUID])
    }

为什么我没有得到最近的设备列表?

您确定您的外设正在使用
transferServiceUUID
为服务做广告吗?尝试使用这些库并将它们添加到您的应用程序中。实际上,我并没有接近测试设备。我正在使用苹果指南来解决这个问题。您能帮我一个忙吗?请先试用
centralManager?。扫描外围设备(服务:无,选项:相同)
@Larme我得到一些设备列表。我不确定他们是否正确。甚至我也无法得到设备的名称。