我们如何使用BLE将garmin设备连接到iOS应用程序

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

我正在开发一个用于心率监测的iOS应用程序,并希望使用蓝牙将garmin设备连接到我的应用程序。

但我无法在Swift中使用(180D服务UUID)列出任何使用Core蓝牙的Garmin设备。

  func startUpCentralManager() {
        print("Initializing central manager")
        centralManager = CBCentralManager(delegate: self, queue: nil)
    }

    func discoverDevices() {
        print("discovering devices")
        let services = [CBUUID(string: HRM_HEART_RATE_SERVICE_UUID),CBUUID(string:HRM_DEVICE_INFO_SERVICE_UUID),CBUUID(string:HRM_DEVICE_BATTERY_LEVEL_SERVICE_UUID),CBUUID(string:CALORIE_SERVICE)]
        centralManager.scanForPeripherals(withServices: services, options: nil)
    }

    //MARK: CBCentralManagerDelegate
    func centralManagerDidUpdateState(_ central: CBCentralManager) {
        print("checking state")
        switch (central.state) {
        case .poweredOff:
            print("CoreBluetooth BLE hardware is powered off")

        case .poweredOn:
           print("CoreBluetooth BLE hardware is powered on and ready")
           blueToothReady = true;

        case .resetting:
            print("CoreBluetooth BLE hardware is resetting")

        case .unauthorized:
            print("CoreBluetooth BLE state is unauthorized")

        case .unknown:
            print("CoreBluetooth BLE state is unknown");

        case .unsupported:
            print("CoreBluetooth BLE hardware is unsupported on this platform");

        }
        if blueToothReady {
            discoverDevices()
        }
    }

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

        let nameOfDeviceFound = (advertisementData as NSDictionary).object(forKey: CBAdvertisementDataLocalNameKey) as? NSString
        print("\(String(describing: nameOfDeviceFound))")
        print("Discovered Peripheral name : ", peripheral.name ?? String())

           if !Utilities.allPeripheralList.contains(peripheral)
           {
               Utilities.allPeripheralList.add(peripheral)
        }
        let deviceObj = DeviceModel()
        deviceObj.deviceName = peripheral.name ?? String()
        deviceObj.UDID = String(format: "%@",(peripheral.identifier).uuidString)
        self.addingPeripheralToGlobalSearchArray(obj: deviceObj)

    }

    func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
        peripheral.delegate = self
        peripheral.discoverServices(nil)
        self.connected = peripheral.state == CBPeripheralState.connected ? "YES" : "NO"
        print("Connection Status : %@", self.connected)
        if self.connected == "YES"{

    Utilities.sharedInstance.goToDashboardTabBarScreen(viewController: self)
        }
    }


func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) {
    //        central.scanForPeripherals(withServices: nil, options: nil)
}

func addingPeripheralToGlobalSearchArray(obj:DeviceModel){
    var isFound:Bool = false
    for i in 0..<Utilities.allDeviceList.count{
        let deviceObj = Utilities.allDeviceList[i] as! DeviceModel
        if obj.UDID == deviceObj.UDID{
            isFound = true
        }
    }

    if !isFound{
        Utilities.allDeviceList.add(obj)
    }
}

以上是我用来列出BLE设备的代码。我能够使用相同的代码安静而不是Garmin设备找到Mio-Fuse设备。

ios swift bluetooth bluetooth-lowenergy garmin
1个回答
0
投票

您需要使用Garmin标准SDK。联系Garmin并注册成为开发人员。您无法使用BLE直接连接,您必须通过Garmin SDK API进行连接。

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