Description
Bug Report
Plugin(s)
@capacitor/network 8.0.1 (same code on main at 87c0bb8 and in 9.0.0-alpha.2)
Capacitor Version
@capacitor/core: 8.5.3
@capacitor/ios: 8.5.3
@capacitor/network: 8.0.1
Xcode 27.1, iOS SDK 27.1
Platform(s)
iOS
Current Behavior
Network.getStatus() doesn't take a reading. It returns whatever the last SCNetworkReachability callback stored.
getStatus (NetworkPlugin.swift:29-32) calls Network.currentStatus() (Network.swift:31-33), which reads Reachability.connection (Reachability.swift:95-105):
public var connection: Connection {
if flags == nil {
try? setReachabilityFlags()
}
switch flags?.connection {Flags are only read synchronously when they're nil (first call, or the initial check in startNotifier). After that, flags is only updated by the reachability callback, so getStatus() answers with the state as of the last callback. Called right after a network change, before that callback has landed on the reachability queue, it returns the previous state.
Expected Behavior
getStatus() reads the current flags when it is called.
Code Reproduction
No sample app needed beyond the plugin's own example:
import { Network } from '@capacitor/network';
Network.addListener('networkStatusChange', s => console.log('event', Date.now(), s));- Run on a device on Wi-Fi.
- Turn Wi-Fi off in Control Center (with cellular off or available).
- Immediately call
await Network.getStatus()(e.g. from a button, or in a tight loop logging every few ms) and compare it to the nextnetworkStatusChangeevent. Until the event arrives,getStatus()keeps returning the previousconnectionType/connected, because nothing re-reads the flags.
Other Technical Details
- This is only about
getStatus()freshness. A PR follows that re-reads the flags synchronously ingetStatus()and keeps the existing SCNetworkReachability implementation. - Moving to
NWPathMonitoris a bigger change and overlaps feat(network): expose connection condition flags #2555, which already adds anNWPathMonitor. Captive-portal / internet-reachability detection is feat(network): Add internet reachability support #2564. Neither changes howgetStatus()reads the cached flags (feat(network): Add internet reachability support #2564'scurrentConnection()still readsreachability.connection).
Additional Context
Older reports with related symptoms, closed during backlog cleanup without a fix: #40 (one commenter there notes getStatus() being out of sync with the actual state).
Activity