IOS Swift服务特性

IOS Swift服务特性,ios,swift,core-bluetooth,Ios,Swift,Core Bluetooth,我正在尝试连接到蓝牙设备(Adable),并查找要附加通知回调的特征数据。问题是,我没有看到列出任何特征。我看到的只是服务本身的属性,没有任何特征 下面是一些代码,显示设备标识和查找服务发生的位置。恕我直言,现在只是调试/破解一个原型 基本上,我正在尝试为arduino/flora模块上的BLE服务设置一个通知程序,以便通过UART传感器发送数据。我有所有的连接工作,但似乎无法让侦听器和更新部分工作。谢谢 func startScanning() { print("Started sca

我正在尝试连接到蓝牙设备(Adable),并查找要附加通知回调的特征数据。问题是,我没有看到列出任何特征。我看到的只是服务本身的属性,没有任何特征

下面是一些代码,显示设备标识和查找服务发生的位置。恕我直言,现在只是调试/破解一个原型

基本上,我正在尝试为arduino/flora模块上的BLE服务设置一个通知程序,以便通过UART传感器发送数据。我有所有的连接工作,但似乎无法让侦听器和更新部分工作。谢谢

func startScanning() {
    print("Started scanning.")
    visiblePeripheralUUIDs.removeAllObjects()
    visiblePeripherals.removeAll(keepCapacity: true)
    tableView.reloadData()
    manager.scanForPeripheralsWithServices(nil, options: nil)
    scanTimer = NSTimer.scheduledTimerWithTimeInterval(10, target: self, selector: Selector("stopScanning"), userInfo: nil, repeats: false)
}



更新了DidDiscoveryCharacteristicsForService,但它仍然没有返回任何内容供我在for循环中解析:

`func peripheral(peripheral: CBPeripheral, didDiscoverCharacteristicsForService service: CBService, error: NSError?) {
        print("GOT TO PERIPHERAL")

    if (peripheral != self.peripheral) {
        // Wrong Peripheral
        print("WrONG PERIPHERAL")
        return
    }

    if (error != nil) {
        print(" GOTS US AN ERROR")
        return
    }

    print("What is service:  \(service)")
    for characteristic in service.characteristics! {
        print("CHARACTERISTIC \(characteristic)")
        if characteristic.UUID == service2 {
            print("WHAT THE F*** BRO \(characteristic as CBCharacteristic)");
            peripheral.setNotifyValue(true, forCharacteristic: characteristic as CBCharacteristic)

            // Send notification that Bluetooth is connected and all required characteristics are discovered
            //self.sendBTServiceNotificationWithIsBluetoothConnected(true)
        }
    }
}
我是不是错过了什么蠢事


Christian

打印(“启动服务发现”)
之后,您需要调用
discoverServices:
。它应该触发
外围设备:DidDiscoveryServices:
然后调用
发现特征:forService:
哪个应该触发
外围设备:DidDiscoveryCharacteristicsForService:错误:
。上面粘贴的更新代码:您没有在
centralManager中调用
外围设备上的
发现服务:
:didConnectPeripheral:
对不起,为了简洁起见,我没有更改,但我确实调用了它。我看到以下内容:以下回调确实执行:func peripal(peripal:cbperipal,didDiscoveryCharacteristicsforService:CBService,error:NSError?)在该回调中,我运行:for characteristic in service.characteristics!{if characteristic.UUID==service1{…..这最终不会计算为true,无论我使用的是CBUUID常量还是UUID的原始字符串。
service1
CBService
UUID还是
CBCharacteristic
UUID?请记录
characteristic.UUID
,以确保正确。
    func peripheral(peripheral: CBPeripheral, didDiscoverCharacteristicsForService service: CBService, error: NSError?) {
    print("GOT TO PERIPHERAL")

    if (peripheral != self.peripheral) {
        // Wrong Peripheral
        print("WrONG PERIPHERAL")
        return
    }

    if (error != nil) {
        print(" GOTS US AN ERROR")
        return
    }

    print("CHECKING ON CHARACTERISTICS \(service.UUID)")


//        for characteristic in service.characteristics! {
//            print("CHARACTERISTIC \(characteristic)")
//            if characteristic.UUID == service2 {
//                print("WHAT THE F*** BRO \(characteristic as CBCharacteristic)");
//                peripheral.setNotifyValue(true, forCharacteristic: characteristic as CBCharacteristic)
//                
//                // Send notification that Bluetooth is connected and all required characteristics are discovered
//                //self.sendBTServiceNotificationWithIsBluetoothConnected(true)
//            }
//        }
    }
`func peripheral(peripheral: CBPeripheral, didDiscoverCharacteristicsForService service: CBService, error: NSError?) {
        print("GOT TO PERIPHERAL")

    if (peripheral != self.peripheral) {
        // Wrong Peripheral
        print("WrONG PERIPHERAL")
        return
    }

    if (error != nil) {
        print(" GOTS US AN ERROR")
        return
    }

    print("What is service:  \(service)")
    for characteristic in service.characteristics! {
        print("CHARACTERISTIC \(characteristic)")
        if characteristic.UUID == service2 {
            print("WHAT THE F*** BRO \(characteristic as CBCharacteristic)");
            peripheral.setNotifyValue(true, forCharacteristic: characteristic as CBCharacteristic)

            // Send notification that Bluetooth is connected and all required characteristics are discovered
            //self.sendBTServiceNotificationWithIsBluetoothConnected(true)
        }
    }
}