Swift 核心蓝牙外围设备不支持';当数据更新时,不要通知中心

Swift 核心蓝牙外围设备不支持';当数据更新时,不要通知中心,swift,core-bluetooth,notify,characteristics,cbperipheralmanager,Swift,Core Bluetooth,Notify,Characteristics,Cbperipheralmanager,我正试图通过BLE发送大数据包。为了做到这一点,我创建了一个特性,当数据发生更改时,它应该通知中心。问题是,显然外围设备在特性中堆积了数据,但显然,一旦特性达到552字节,它就不能存储更多的数据 中央处理器只接收552字节,并调用函数didReceiveRead3次(我一次传输200字节,所以3次是600字节,但只有552字节通过(我认为这是iOS 10以来的限制))。 此代码还仅打印一次未处理的特征UUID:00000000-0000-0000-0000-000000000000,并设法将我的

我正试图通过BLE发送大数据包。为了做到这一点,我创建了一个特性,当数据发生更改时,它应该通知中心。问题是,显然外围设备在特性中堆积了数据,但显然,一旦特性达到552字节,它就不能存储更多的数据

中央处理器只接收552字节,并调用函数
didReceiveRead
3次(我一次传输200字节,所以3次是600字节,但只有552字节通过(我认为这是iOS 10以来的限制))。 此代码还仅打印一次未处理的特征UUID:00000000-0000-0000-0000-000000000000,并设法将我的特征的
设置为
。另外,
didUpdateNotificationStateFor
只调用一次

我想知道为什么我的特点是将数据堆积起来,而不是像我想的那样一次发送200字节。

外设使用的代码为: (函数chunk只获取数据和我们想要的chunk大小的int,并返回chunk和数据减去获取的chunk)

中央银行的代码是:

public func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
    guard let characteristics = service.characteristics else { return }

    print("Characteristic:")
    for characteristic in characteristics {
        print(characteristic)
        if characteristic.properties.contains(.read) {
            print("\(characteristic.uuid): properties contains .read")
            peripheral.readValue(for: characteristic)
        }
        if characteristic.properties.contains(.notify) {
            print("\(characteristic.uuid): properties contains .notify")
            peripheral.setNotifyValue(true, for: characteristic)
            print("ok for: \(characteristic)")
        }
    }
}

public func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {

    print("Unhandled Characteristic UUID: \(characteristic.uuid)")
    print(error)
}
public func peripheral(_ peripheral: CBPeripheral, didUpdateNotificationStateFor characteristic: CBCharacteristic, error: Error?) {

    print(characteristic)
    print(characteristic.value)
}
请随意索取更多代码


谢谢。

你实施了吗?@Paulw11不,我没有。但是一旦我这样做了,我就意识到func
didsubscribebeto
是在3
didReceiveRead
调用之后调用的。我还在
didsubscribebeto
中打印中心和特征。两者都是正确的。@w11。似乎从来没有调用过
toUpdateSubscribers
。我是否需要调用某个函数来告诉我的外设,以指示他已完成数据更新。它可以解释特征中的数据拥塞。你能显示你的didSubscribeTo代码吗?您的外围设备负责跟踪已订阅特征的central,并在您有新数据时通知这些central。My
didSubscribeTo
code实际上只是
print(“订阅:\(中心)和特征:\(特征)”)
其中有输出
订阅:和特征:
。我是否需要在此函数中添加其他内容?
public func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
    guard let characteristics = service.characteristics else { return }

    print("Characteristic:")
    for characteristic in characteristics {
        print(characteristic)
        if characteristic.properties.contains(.read) {
            print("\(characteristic.uuid): properties contains .read")
            peripheral.readValue(for: characteristic)
        }
        if characteristic.properties.contains(.notify) {
            print("\(characteristic.uuid): properties contains .notify")
            peripheral.setNotifyValue(true, for: characteristic)
            print("ok for: \(characteristic)")
        }
    }
}

public func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {

    print("Unhandled Characteristic UUID: \(characteristic.uuid)")
    print(error)
}
public func peripheral(_ peripheral: CBPeripheral, didUpdateNotificationStateFor characteristic: CBCharacteristic, error: Error?) {

    print(characteristic)
    print(characteristic.value)
}