Use fallback DNS on iOS (Objective-c)

Viewed 86

I'm having a DNS problem in some internet providers in my country and the host configured in my app is not found.

For that, in ANDROID, I found a solution by adding a property in the Java VM.

protected void init() { 
    System.setProperty("dns.server", "8.8.8.8");
    super.init(); 
}

Is there any similar solution for iOS? Mainly using objective-c? I didn't find anything searching on google.

1 Answers

Yes. Using a command-line tool as an API is generally a bad idea, even more so when there’s a full-featured public API behind that tool.

As to why you’re seeing different behaviour with

networksetup

, that’s a surprisingly complex issue. The tool calls SystemConfiguration framework, which uses Authorisation Services to authorise the operation (see the discussion around

SCPreferencesCreateWithAuthorization

). Authorization Services is rather complex, but one of its features is the ability to use an existing credential to satisfy a new authorisation request. Back in the day I wrote a Q&A to explain the ins’n’outs of this (QA1277 Security Credentials) but to this day I’m not 100% sure I got it right

Related