removeNotifyListener method
移除通知监听
Implementation
Future<void> removeNotifyListener(
Uuid service, Uuid characteristic, NotifyListener listener) async {
String key = service.toString().toLowerCase() +
"-" +
characteristic.toString().toLowerCase();
_NotifyData? notifyData;
if (notifyMap.containsKey(key)) {
notifyData = notifyMap[key]!;
}
if (notifyData == null) {
return;
}
notifyData.removeListener(listener);
//如果已经没有监听了,则清空之前的订阅
if (notifyData.listenerLength == 0) {
notifyMap.remove(key);
await notifyData.streamSubscription?.cancel();
if (Platform.isIOS) {
//TODO IOS底层应该是有bug,cancel的停止没有等到,所以这里手动延时下,看之后如何从底层修改掉这个问题。
await Future.delayed(const Duration(milliseconds: 200));
}
}
}