Skip to content

Commit c2fb43d

Browse files
authored
Ignore NotReadyException when stopping observations on Apple (#101)
1 parent 151e54d commit c2fb43d

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

core/src/appleMain/kotlin/Observers.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow
66
import kotlinx.coroutines.flow.collect
77
import kotlinx.coroutines.flow.flow
88
import platform.Foundation.NSData
9+
import platform.Foundation.NSLog
910

1011
/**
1112
* Manages observations for the specified [peripheral].
@@ -55,7 +56,13 @@ internal class Observers(
5556
}
5657
} finally {
5758
if (observers.decrementAndGet(characteristic) < 1) {
58-
peripheral.stopNotifications(characteristic)
59+
try {
60+
peripheral.stopNotifications(characteristic)
61+
} catch (e: NotReadyException) {
62+
// Silently ignore as it is assumed that failure is due to connection drop, in which case the system
63+
// will clear the notifications.
64+
NSLog("Stop notification failure ignored.")
65+
}
5966
}
6067
}
6168
}

0 commit comments

Comments
 (0)