Due to the needs of daily development, we need to listen to the changes in some of OSX's system settings, to achieve the synchronization of software program settings, we can listen to the following functions to change the system settings:
#include <SystemConfiguration/SystemConfiguration.h>
//------------------------------------------------------------------
Scdynamicstoreref Dynstore;
Scdynamicstorecontext context = {0, this, NULL, NULL, NULL};
Dynstore = Scdynamicstorecreate (Kcfallocatordefault,
Cfbundlegetidentifier (Cfbundlegetmainbundle ()),
systemproxychangecallback,//Custom callback function, note "1"
&context);
Const CFSTRINGREF Keys[3] = {cfstr ("state:/network/global/proxies")};//get system proxy settings, note "2"
Cfarrayref Watchedkeys = cfarraycreate (Kcfallocatordefault,
(const void * *) keys,
1,
&kcftypearraycallbacks);
if (Scdynamicstoresetnotificationkeys (Dynstore, NULL, Watchedkeys))
{
Cfrelease (Watchedkeys);
Cfrunloopsourceref rlsrc = Scdynamicstorecreaterunloopsource (Kcfallocatordefault, DynStore, 0);
Cfrunloopaddsource (Cfrunloopgetcurrent (), RLSRC, Kcfrunloopdefaultmode);
Cfrelease (RLSRC);
}
Else
{
Cfrelease (Watchedkeys);
Cfrelease (Dynstore);
Dynstore = NULL;
}
//------------------------------------------------------------------
Cfrunlooprun (); You need to call this function in the program to listen to the effect
//================================================
Note "1", when the system settings are changed, the callback function will be triggered, according to the specific needs of the relevant operation processing
void Systemproxychangecallback (Scdynamicstoreref store, cfarrayref changedkeys,void *info)
{
}
Note "2", here the demo program for monitoring network agents to change the properties of the settings, other property values can be consulted:
Https://developer.apple.com/library/mac/documentation/Networking/Conceptual/SystemConfigFrameworks/SC_ Understandschema/sc_understandschema.html
OSX Monitoring System Network settings