You can access the network settings through the SystemConfiguration module, which will help you access the system settings. Saving is currently in the default location /Library/Preferences/SystemConfiguration/preferences.plist .
From then on, you can receive notifications from SCDynamicStore on SCDynamicStoreNotifyValue(_:_:) or receive the value SCDynamicStoreCopyValue(_:_:) .
Example for direct search of the current primary network service:
var store = SCDynamicStoreCreate(nil, "Example" as CFString, nil, nil) var global = SCDynamicStoreCopyValue(store, "State:/Network/Global/IPv4" as CFString)! var pref = SCPreferencesCreate(nil, "Example" as CFString, nil) var service = SCNetworkServiceCopy(pref!, global["PrimaryService"] as! CFString) var interface = SCNetworkServiceGetInterface(service!) SCNetworkInterfaceGetInterfaceType(interface!)
Or create a dynamic repository with a callback and set the notification keys to receive notifications, since every time the primary network service changes the notification, it will work:
var callback: SCDynamicStoreCallBack = { (store, _, _) in } var store = SCDynamicStoreCreate(nil, "Example" as CFString, callback, nil) SCDynamicStoreSetNotificationKeys(store!, ["State:/Network/Global/IPv4"] as CFArray, nil)
Legendecas
source share