2

is there any system event which I can use in my program to detect a network change on macOS? I would like to call a function if the network state change, without having a lookup every x seconds in my program. Currently I'm using 'scheduledTimer' to make a lookup...

Is there a better solution for that?

Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165
MOE
  • 769
  • 6
  • 19
  • What's a "network change" exactly? A change of WiFi network? A new network interface plugged in? A change in a network connection's DNS servers? – Alexander Jul 25 '18 at 06:27
  • 1
    I would like to know if the device is connected to ethernet or wi-fi or nothing. Every time this state change (user plugged in the ethernet or turned of the wi-fi), the application must do some tasks... – MOE Jul 25 '18 at 06:31
  • Possible duplicate of. https://stackoverflow.com/q/41590562/1187415. Also: https://stackoverflow.com/q/15535571/1187415, https://stackoverflow.com/q/2910121/1187415 – Martin R Jul 25 '18 at 06:49
  • You have to be even more specific. Are you particularly concerned about connecting/disconnecting to the internet? What happens if a user who's connected to a working, internet-reachable WiFi connection, and then plugs in an ethernet connection to an intranet. Do you care about that? – Alexander Jul 25 '18 at 07:18
  • I just want to be informed if the user connect/disconnect a network. Then I would do the check if the user is in the company intranet in my attached function. I noticed that macOS always prefer a ethernet connection, so in the case that the user has also wi-fi enabled it would use the ethernet connection. and if this one is a intranet connection my function can do the rest... – MOE Jul 25 '18 at 09:46

0 Answers0