Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.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
我们如何使用BLE将garmin设备连接到iOS应用程序_Ios_Swift_Bluetooth_Bluetooth Lowenergy_Garmin - Fatal编程技术网

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

我们如何使用BLE将garmin设备连接到iOS应用程序,ios,swift,bluetooth,bluetooth-lowenergy,garmin,Ios,Swift,Bluetooth,Bluetooth Lowenergy,Garmin,我正在开发一个用于心率监测的iOS应用程序,希望使用蓝牙将garmin设备连接到我的应用程序 但我无法列出任何在Swift中使用核心蓝牙的Garmin设备(180D服务UUID) func startUpCentralManager(){ 打印(“初始化中央管理器”) centralManager=CBCentralManager(代理:self,队列:nil) } func discoverDevices(){ 打印(“发现设备”) let services=[CBUUID(字符串:HRM\U

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

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

func startUpCentralManager(){
打印(“初始化中央管理器”)
centralManager=CBCentralManager(代理:self,队列:nil)
}
func discoverDevices(){
打印(“发现设备”)
let services=[CBUUID(字符串:HRM\U心率\U服务\U UUID)、CBUUID(字符串:HRM\U设备\U信息\U服务\U UUID)、CBUUID(字符串:HRM\U设备\U电池\U水平\U服务\U UUID)、CBUUID(字符串:卡路里\U服务)]
centralManager.ScanFor外围设备(带服务:服务,选项:无)
}
//马克:CBCentralManagerDelegate
func CentralManager数据状态(uCentral:CBCentralManager){
打印(“检查状态”)
开关(中央状态){
案例.断电:
打印(“蓝牙核心硬件已关闭”)
案例.poweredOn:
打印(“蓝牙核心硬件已通电并准备就绪”)
blueToothReady=正确;
案例.重置:
打印(“蓝牙核心硬件正在重置”)
案件.未经授权:
打印(“核心状态未经授权”)
案件.未知:
打印(“核心状态未知”);
案例。不支持:
打印(“此平台不支持蓝牙核心硬件”);
}
如果蓝牙准备好了{
发现设备()
}
}
func centralManager(ucentral:CBCentralManager,didDiscover peripal:cbperipal,advertisementData:[String:Any],rssi-rssi:NSNumber){
将NameOfDeviceFund=(作为NSDictionary的advertisementData)。对象(forKey:CBAdvertisementDataLocalNameKey)作为?NSString
打印(\(字符串(描述:NameOfDeviceFund)))
打印(“发现的外围设备名称:”,Peripheral.name??String())
if!Utilities.allPeripheralList.contains(外围设备)
{
实用程序.所有外围设备列表.添加(外围设备)
}
设deviceObj=DeviceModel()
deviceObj.deviceName=peripheral.name??字符串()
deviceObj.UDID=String(格式:“%@”,(peripheral.identifier.uuiString)
自添加外围设备全局搜索阵列(obj:deviceObj)
}
func centralManager(uCentral:CBCentralManager,didConnect外围设备:CBPeripheral){
peripheral.delegate=self
外围设备。发现服务(无)
self.connected=peripheral.state==cbperipheraldstate.connected?“是”:“否”
打印(“连接状态:%@”,自连接)
如果self.connected==“是”{
Utilities.sharedInstance.goToDashboardTabBarScreen(viewController:self)
}
}
func centralManager(uCentral:CBCentralManager,DidDisconnect外围设备:CBPeripheral,错误:错误?){
//central.ScanFor外围设备(服务:无,选项:无)
}
func添加外围设备全局搜索阵列(对象:设备模型){
变量isFound:Bool=false

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

如何查找您的设备?您是否创建了CBCentralManager?您是否调用scanForPeripheralsWithServices?之后是否收到任何回调?是的,我正在使用g CBCentralManager,但我无法列出任何Garmin设备。你能发布一段代码,说明你如何找到它吗?例如,你如何判断它是Garmin设备?通过公开的服务UUID?通过名称?@fspirit我已将问题与代码一起更新。尝试使用
centralManager.scanForPeripherals(使用services:nil,options:nil)
如果您的设备没有公布他拥有目标服务(它可能会隐藏它,没有义务),那么您将不会发现它,因为您只扫描了这些服务。
  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)
    }
}