Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.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
Ios 为什么我不能通过CoreBluetooth获取配对设备的实例?_Ios_Swift_Core Bluetooth_External Accessory - Fatal编程技术网

Ios 为什么我不能通过CoreBluetooth获取配对设备的实例?

Ios 为什么我不能通过CoreBluetooth获取配对设备的实例?,ios,swift,core-bluetooth,external-accessory,Ios,Swift,Core Bluetooth,External Accessory,我有一个名为later scanner的设备和其他名为later stone的设备。扫描仪可以扫描石头并在内置显示器上显示它们的信息。扫描仪可以通过蓝牙发送石头信息,我想读取这些数据并在我的应用程序中使用。我启动了代码连接实现,但发现了一个问题。这是我的密码: import UIKit import CoreBluetooth class BluetoothViewController: UIViewController { var manager:CBCentralManager!

我有一个名为later scanner的设备和其他名为later stone的设备。扫描仪可以扫描石头并在内置显示器上显示它们的信息。扫描仪可以通过蓝牙发送石头信息,我想读取这些数据并在我的应用程序中使用。我启动了代码连接实现,但发现了一个问题。这是我的密码:

import UIKit
import CoreBluetooth

class BluetoothViewController: UIViewController {

    var manager:CBCentralManager!
    var peripheral:CBPeripheral!

    override func viewDidLoad() {
        super.viewDidLoad()

        manager = CBCentralManager(delegate: self, queue: nil)
    }
}

extension BluetoothViewController: CBCentralManagerDelegate {

    func centralManagerDidUpdateState(_ central: CBCentralManager) {
        if central.state == .poweredOn {
            central.scanForPeripherals(withServices: nil, options: nil)
        }
        else {
            print("Bluetooth not available.")
        }
    }

    func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
        print("peripheral \(peripheral)")
        print("rssi \(RSSI)")
        print("advertisementData: \(advertisementData)")
        print("--------")
    }

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

    func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?) {
        print(peripheral)
    }

    func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) {
        print(peripheral)
    }
}

extension BluetoothViewController: CBPeripheralDelegate {

}
问题是扫描仪没有出现在中

func centralManager_uCentral:CBCentralManager,DidDiscovery外围设备:CBPeripal,广告数据:[字符串:任意],rssi rssi:NSNumber

func centralManager_uCentral:CBCentralManager,didConnect外围设备:CBPeripheral

不要打电话

请注意,我的iPhone与扫描仪连接,扫描仪告诉我连接正常

我想要实现什么? 我想创建viewcontroller,用于检查扫描仪是否已连接

if connected then
    get scan information
else
    find device and connect
get scan information
请帮帮我

编辑 在我的扫描仪中,设备未显示。 但这种方法非常有效


也许使用CoreBluetooth是一种错误的方式。什么更好。如果上述应用程序的创建者能够与电子通信,则有可能做到这一点。

谢谢@Paulw11的评论,我意识到我的扫描仪使用iPod附件协议。为了确保导入ExternalAccessority framework并检查设备

    EAAccessoryManager.shared().showBluetoothAccessoryPicker(withNameFilter: nil, completion: nil)

调用此功能后,我看到了附件设备的列表,我的扫描仪也在其中。

您的扫描仪设备是否宣传了可扩展服务?从应用商店试用LightBlue应用。@Paulw11如果否怎么办?您需要显式连接到DidDiscoveryPeripal中的外围设备,以便调用didConnect方法。但不确定为什么你的设备没有被发现。这些石头到底是什么?石头是无关紧要的。我想将我的设备与扫描仪连接,但它没有出现在DidDiscovery外围设备中。该设备的手册表明它使用iPod附件协议,因此该设备处于MFi程序下。这意味着它使用外部附件框架和传统蓝牙。