How to get network connection status in apple watch standalone application?

303 views Asked by At

Using NWPathMonitor, I get network information in watch simulator (with usesInterfaceType) and it showing right status, but in real device it's not working. It alway showing no network. I developed independent watch application. Please check below code that I write for this:

let monitor = NWPathMonitor()

monitor.pathUpdateHandler = { path in

    if path.status == .satisfied {

        print("We're connected!")                
        if path.usesInterfaceType(.wifi) {
            print("It's WiFi!")
        } else if path.usesInterfaceType(.cellular) {
            print("3G/4G FTW!!!")
        } else if path.usesInterfaceType(.wiredEthernet) {
            print("wiredEthernet")
        }else if path.usesInterfaceType(.loopback) {
            print("loopback")
        }else if path.usesInterfaceType(.other) {
            print("other")
        }

    }
    else {
        print("No connection.")
    }
}

let queue = DispatchQueue(label: "InternetConnectionMonitor")
monitor.start(queue: queue)
0

There are 0 answers