How to get network status in apple watch??

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 indepedant watch application

Could you show the code ?


See here for details to check you use it as required:

h ttps://www.hackingwithswift.com/example-code/networking/how-to-check-for-internet-connectivity-using-nwpathmonitor

Thank you for coment.

I folow same page for developing the code.And you can check by below:


monitor.pathUpdateHandler = { path in

if path.status == .satisfied {

print("We're connected!")

self.lbl_Network_status.setText("Connected".localized)

self.image_Network.setImage(UIImage(named: "ic_network"))

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

self.lbl_Network_status.setText("Not Connected".localized)

self.image_Network.setImage(UIImage(named: "ic_network_not"))

}

// print(path.isExpensive)

// Only ipv4 Connection is support .Connection dns and ipv6 not support

}

let queue = DispatchQueue(label: "InternetConnectionMonitor")

// let queue = DispatchQueue.global(qos: .background)

monitor.start(queue: queue)

What print results do you get (on watch, not simulator) ?


To ease test, you could create a testLabel on the watch where to display instead of logging via print.

As code show it's else part execute and "Not Connected" status show.

And I print status and also set in Label property to display but in both case is "Not Connected".


Any other way to get network property in apple watch and I developed standalone application(Independ watch app).

Could you tell what is the status:

                print("No connection.", status)

By status, I mean network status (like connected or not connected).

My point was : what status do you get with the print statement ?

This still doesn't work on an Apple Watch. Anyone have an actual solution? Why would it not work on the device but it does on the simulator?

See my response on this thread.

How to get network status in apple watch??
 
 
Q