Subscribe to macOS Proxy Configuration Changes
Watch the relevant SystemConfiguration dynamic-store keys and refresh a custom transport's proxy policy when macOS reports changes.
A transport using a startup-only proxy snapshot can remain stale after a network or location change. For a macOS SystemConfiguration subscription, keep this lifecycle explicit:
- Create an SCDynamicStore session with a callback.
- Register exact keys or patterns using
SCDynamicStoreSetNotificationKeys. They are separate arrays. The global proxy key isState:/Network/Global/Proxies; add service-specific inputs only where the transport consumes them. - Arrange callback delivery through
SCDynamicStoreSetDispatchQueueor the appropriate run-loop source. Registering names alone does not run the callback. - On notification, reread effective configuration and update subsequent work. The changed-key list is not itself the complete new policy.
- At shutdown, disable dispatch delivery with a null queue before releasing owned resources. Keep the store and callback context alive until then.
Apple's header defines an empty changed-key list as a dynamic-store server restart. Refresh relevant state and discard assumptions based on the previous contents in that case too.
This is a public macOS API approach. Apple's headers mark the corresponding functions private SPI for iOS, so the same subscription is not a public iOS application interface.