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

Abierto
#2,620 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 29 días

@kcjonson ya está trabajando en esto.

Desde el 22/10/2026.

  • #2622 de @kcjonson — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
ios, swift
Área
mobile

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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).

Lenguaje dominante
Java
Estrellas
688
Forks
692
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de ionic-team/capacitor-plugins

Todos los issues de ionic-team/capacitor-plugins

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.