bug(network): iOS getStatus() returns the last reachability callback value instead of reading current flags

Aperta
#2,620 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 29 giorni

@kcjonson ci sta già lavorando.

Dal 22/10/2026.

  • #2622 di @kcjonson — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
ios, swift
Ambito
mobile

Direzione di ricerca

Start with NetworkPlugin.swift lines 29–32, then follow Network.currentStatus() into Network.swift and Reachability.swift lines 95–105 to see how flags are read and updated. Reproduce by calling Network.getStatus() immediately after changing network state and compare it with the next networkStatusChange event. Done means getStatus() reads current flags when called; an open linked pull request (#2622) is already addressing this issue.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

platform: ios

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));
  1. Run on a device on Wi-Fi.
  2. Turn Wi-Fi off in Control Center (with cellular off or available).
  3. Immediately call await Network.getStatus() (e.g. from a button, or in a tight loop logging every few ms) and compare it to the next networkStatusChange event. Until the event arrives, getStatus() keeps returning the previous connectionType/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 in getStatus() and keeps the existing SCNetworkReachability implementation.
  • Moving to NWPathMonitor is a bigger change and overlaps #2555, which already adds an NWPathMonitor. Captive-portal / internet-reachability detection is #2564. Neither changes how getStatus() reads the cached flags (#2564's currentConnection() still reads reachability.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).

Lingua principale
Java
Stelle
688
Fork
692
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ionic-team/capacitor-plugins

Tutte le issue di ionic-team/capacitor-plugins

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.