Skip to content

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

Open

Description

@kcjonson

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions