Files

49 lines
1.9 KiB
Diff

diff --git a/android/src/main/java/expo/modules/network/NetworkModule.kt b/android/src/main/java/expo/modules/network/NetworkModule.kt
index 5e513271533a6c99bcfe8fff245e84c80ac55621..f7353c3d2eb01798b083359e1554556303bf0f0e 100644
--- a/android/src/main/java/expo/modules/network/NetworkModule.kt
+++ b/android/src/main/java/expo/modules/network/NetworkModule.kt
@@ -89,6 +89,11 @@ class NetworkModule : Module() {
}
}
+ // Android reports a lifted network block only through this callback.
+ override fun onBlockedStatusChanged(network: android.net.Network, blocked: Boolean) {
+ asyncEmitNetworkState(DELAY_MS)
+ }
+
override fun onCapabilitiesChanged(network: android.net.Network, networkCapabilities: NetworkCapabilities) {
asyncEmitNetworkState(DELAY_MS)
}
diff --git a/ios/NetworkModule.swift b/ios/NetworkModule.swift
index ce150f792f0a717696b24d3930d8ea55b1dc12a6..ec1d2cdd11861f8862ba58c20fd7f1c75845efdb 100644
--- a/ios/NetworkModule.swift
+++ b/ios/NetworkModule.swift
@@ -101,10 +101,18 @@ public final class NetworkModule: Module {
// since we want to wait for the result to be updated once:
let tempMonitor = NWPathMonitor()
var tempPath: NWPath?
+ let pathLock = NSLock()
let semaphore = DispatchSemaphore(value: 0)
tempMonitor.pathUpdateHandler = { updatedPath in
+ // Cancellation does not drain queued updates. Publish only the first path
+ // and synchronize its retain with the caller reading it on another queue.
+ pathLock.lock()
+ defer { pathLock.unlock() }
+ guard tempPath == nil else {
+ return
+ }
tempPath = updatedPath
semaphore.signal() // Notify that we got the path
}
@@ -122,6 +130,8 @@ public final class NetworkModule: Module {
return nil
}
+ pathLock.lock()
+ defer { pathLock.unlock() }
return tempPath
}