Sunday, November 8, 2026
HomeiOS Developmentios - Swift community monitor switches .happy and .unhappy statuses

ios – Swift community monitor switches .happy and .unhappy statuses

[ad_1]

I am making an attempt to observe the community entry of an iOS app.

After I run the simulator for a primary time with wifi turned ON I get the fitting message “We’re linked!”.

However after I swap OFF the wifi I get the identical message “We’re linked!”.

If I swap it on once more I get the “No connection.” message.

If I proceed to modify the community on and off I get the alternative standing of the particular state of the wifi.

Any concepts what am I doing flawed? Here is the code:

import Basis
import Community

last class NetworkMonitor: ObservableObject {
    
    let queue = DispatchQueue(label: "NetworkMonitor")
    let monitor = NWPathMonitor()
    
    init() {
        monitor.pathUpdateHandler = { path in
            if path.standing == .happy {
                print("We're linked!")
            } else {
                print("No connection.")
            }
        }
        monitor.begin(queue: queue)
    }
    
}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments