大致代码如下:
String SERVICE_UUID = "0000F000-0000-1000-8000-00805f9b34fb";
String NOTIFICATION_CHARACTERISTIC_UUID = "0000F001-0000-1000-8000-00805f9b34fb";
_notifyCharacteristic = QualifiedCharacteristic(
serviceId: Uuid.parse(SERVICE_UUID),
characteristicId: Uuid.parse(NOTIFICATION_CHARACTERISTIC_UUID),
deviceId: event.deviceId);
subscribeToCharacteristic(_notifyCharacteristic)
.listen((data) {
//
}, onError: (dynamic error) {
//
});
在android中,subscribeToCharacteristic可以正常监听notification的数据,但是在ios却是无法监听的,原因出在UUID的定义上,在IOS中,16bits的UUID需要定义为16位,如下:
String SERVICE_UUID = "F000";
String NOTIFICATION_CHARACTERISTIC_UUID = "F001";
这样子IOS就正常了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)