0

I can set app specific properties with NSUserDefaults, but not System Properties such as proxxy/port.

Her'e how I do it in Java. How can I do this with Swift 2?

// Set proxy/port in system properties
System.setProperty("http.proxyHost", "12.345.67.89");
System.setProperty("http.proxyPort", "1234");
System.setProperty("java.net.useSystemProxies", "true");

// Authenticate
System.setProperty("http.proxyUser", "someusername");    
System.setProperty("http.proxyPassword", "somepassword");

System.setProperty("http.proxySet", "true");
dbconfession
  • 1,147
  • 2
  • 23
  • 36
  • Is this a sandboxed .app, and what was the behavior when you tried setting the values in Swift? – l'L'l Jul 17 '16 at 19:09
  • That's my question. How do you set system properties in swift? The Java is standard in any app I make that requires proxy. – dbconfession Jul 17 '16 at 20:39
  • Sandboxed boxed apps won't allow changing `NSUserDefaults` for any application other than itself. – l'L'l Jul 17 '16 at 20:43
  • Then how do I set proxy and port and authorize credentials? – dbconfession Jul 17 '16 at 21:00
  • There's no simple answer to that; I would start by reading the [Apple App Sandbox Design Guide](https://developer.apple.com/library/mac/documentation/Security/Conceptual/AppSandboxDesignGuide/DesigningYourSandbox/DesigningYourSandbox.html#//apple_ref/doc/uid/TP40011183-CH4-SW6) then take a look at this [question](http://stackoverflow.com/a/10765768), and go from there. Some apps just aren't good candidates for sandboxing and the developers often offer them outside of the App Store. – l'L'l Jul 17 '16 at 21:09
  • Are you sure? This is OSX btw. Not iOS. The reason I switched from doing this in iOS to OS X is because o know for sure it can be done. I've done it in Java on OS X. – dbconfession Jul 17 '16 at 22:08
  • Apparently you don't read. If you're sure it can be done then why would you ask this question, it makes no sense... – l'L'l Jul 17 '16 at 22:11
  • I "read" everything. Perhaps there's more than that explanation for me not understanding? Perhaps you're not being clear, or I'm not understanding what you're saying. If you'd be so kind, could you clarify? – dbconfession Jul 17 '16 at 22:12
  • But yes, I'll read the documentation again. Thank you. – dbconfession Jul 17 '16 at 22:13
  • I think it's you not being clear, as you never even answered the question in my first comment. – l'L'l Jul 17 '16 at 22:14
  • No it's not sandboxed. – dbconfession Jul 17 '16 at 22:30
  • I won't even ask why you didn't mention that this entire discussion. – l'L'l Jul 17 '16 at 22:35
  • Because I thought you used the wrong word and meant "playgrounds". I was not aware of what sandbox meant. Thank you, I appreciate the link. – dbconfession Jul 17 '16 at 22:36
  • Now that you mention it, *Apple* used the wrong word; I can see how someone *might* confuse the meaning of Sandbox v Playground, although in computing the term "Sandbox" is always associated with the security mechanism for separating running programs. – l'L'l Jul 17 '16 at 22:39
  • To answer your question, yes system settings can be manipulated if the app is not in a sandbox. – l'L'l Jul 17 '16 at 22:47
  • I mentioned how yesterday, although it appears you abandoned [that question](http://stackoverflow.com/questions/38413748/swift-2-osx-how-do-i-implement-proxy-settings-with-nsurlsession) and created another one. – l'L'l Jul 17 '16 at 23:00
  • I switched to NSURLSession and added configuration but that didn't work. – dbconfession Jul 17 '16 at 23:02
  • I'll repost that code with your suggestion when o get home tomorrow. – dbconfession Jul 17 '16 at 23:04
  • Your comment on that thread doesn't answer how to set system preferences. Also, I followed up with a question. – dbconfession Jul 18 '16 at 00:42
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/117624/discussion-between-dbconfession-and-lll). – dbconfession Jul 18 '16 at 15:55

0 Answers0