繁体   English   中英

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

[英]How can we connect garmin devices to iOS Application using BLE

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

但是我无法列出使用(180D Service UUID)在Swift中使用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设备的代码。 我可以使用相同的代码和平度找到Mio-Fuse设备,但找不到Garmin设备。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM