A demo for changing system proxy settings.
After click “Enable System Proxy”, a dialog for requesting auhorization will be popped up, and subsequent clicks won't popup again, which is fine.
But if we Quit and Relaunch the app, the auhorizating dialog will be popped up again.
How can we authorize once and for all?
-
Launch demo app “SystemProxySettingsDemo”
-
Click “Enable System Proxy” button, the auhorizating dialog will be popped up
-
The SOCKS proxy setting in system network preferences will be changed to host: 127.0.0.1, port: 8888
-
Click “Disable System Proxy” button to clear system network preferences proxy
-
Quit the app, and launch it again
-
Click “Enable System Proxy” button, the auhorizating dialog will be popped up, again
-
GitHub repository: https://github.com/codinn/SystemProxySettingsDemo
-
Apple official sample: https://developer.apple.com/library/content/samplecode/EvenBetterAuthorizationSample/Introduction/Intro.html
-
File “ViewController.swift”: Creating an authorization reference, Requesting Authorization, System Network Preferences Proxy settings.
Function define:
// requesting authorization with “AuthorizationCopyRights”
// set system network preferences proxy with “SCPreferencesCreateWithAuthorization” and “SCPreferencesPathSetValue”
func socksProxySet(enabled: Bool)
- File “CommonAuthorization.swift”: set / get authorization policy database entries
- File “codinnDemoRightRemove.sh”: clear policy database entries belongs to demo app
- I've tried storing the Authorization Rights to the policy database with “AuthorizationRightSet” (setting policy database rule attribute “timeout” as 0, or 3600, or remove the attribute “timeout”), but it does not work
- Also tried using
kAuthorizationRuleClassAllow
orkAuthorizationRuleAuthenticateAsAdmin
as value for parameterrightDefinition
of functionAuthorizationRightSet
, but it does not work either