Last active
May 24, 2022 07:39
-
-
Save aiqinxuancai/a53582e28945e033ceafdf02bdd27ec4 to your computer and use it in GitHub Desktop.
iOS对App自身设置安全DNS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Network/Network.h> | |
if (@available(iOS 14.0, *)) { | |
nw_privacy_context_t parameters = _nw_privacy_context_default_context; | |
nw_endpoint_t address1 = nw_endpoint_create_host("223.5.5.5", "443"); | |
nw_endpoint_t address2 = nw_endpoint_create_host("223.6.6.6", "443"); | |
nw_endpoint_t address3 = nw_endpoint_create_host("2400:3200::1", "443"); | |
nw_endpoint_t address4 = nw_endpoint_create_host("2400:3200:baba::1", "443"); | |
nw_resolver_config_t resolverConfig = nw_resolver_config_create_https(nw_endpoint_create_url("https://223.5.5.5/dns-query")); | |
nw_resolver_config_add_server_address(resolverConfig, address1); | |
nw_resolver_config_add_server_address(resolverConfig, address2); | |
nw_resolver_config_add_server_address(resolverConfig, address3); | |
nw_resolver_config_add_server_address(resolverConfig, address4); | |
nw_privacy_context_require_encrypted_name_resolution(parameters, true, resolverConfig); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment