diff --git a/MSDKDns.xcodeproj/project.pbxproj b/MSDKDns.xcodeproj/project.pbxproj index 6ba6857..3b2f28c 100644 --- a/MSDKDns.xcodeproj/project.pbxproj +++ b/MSDKDns.xcodeproj/project.pbxproj @@ -1047,7 +1047,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.8.0; + MARKETING_VERSION = 1.8.1; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1094,7 +1094,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.8.0; + MARKETING_VERSION = 1.8.1; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", @@ -1137,7 +1137,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.8.0; + MARKETING_VERSION = 1.8.1; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1179,7 +1179,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.8.0; + MARKETING_VERSION = 1.8.1; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", @@ -1228,7 +1228,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.8.0; + MARKETING_VERSION = 1.8.1; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1276,7 +1276,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.8.0; + MARKETING_VERSION = 1.8.1; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", @@ -1314,7 +1314,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.8.0; + MARKETING_VERSION = 1.8.1; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( @@ -1354,7 +1354,7 @@ LINK_WITH_STANDARD_LIBRARIES = NO; MACH_O_TYPE = mh_object; MACOSX_DEPLOYMENT_TARGET = ""; - MARKETING_VERSION = 1.8.0; + MARKETING_VERSION = 1.8.1; OTHER_CFLAGS = "-fembed-bitcode"; OTHER_LDFLAGS = ( "-ObjC", diff --git a/MSDKDns/CacheManager/MSDKDnsManager.m b/MSDKDns/CacheManager/MSDKDnsManager.m index 7822b6f..0f028bb 100644 --- a/MSDKDns/CacheManager/MSDKDnsManager.m +++ b/MSDKDns/CacheManager/MSDKDnsManager.m @@ -1155,14 +1155,9 @@ - (void)detectHttpDnsServers { } - (NSString *)currentDnsServer { - // int index = self.serverIndex; - // if (index < [[[MSDKDnsParamsManager shareInstance] msdkDnsGetServerIps] count]) { - // return [[[MSDKDnsParamsManager shareInstance] msdkDnsGetServerIps] objectAtIndex:index]; - // } - // return [[MSDKDnsParamsManager shareInstance] msdkDnsGetMDnsIp]; int index = self.serverIndex; - if (index < [self.dnsServers count]) { - return [self.dnsServers objectAtIndex:index]; + if (self.dnsServers != nil && [self.dnsServers count] > 0 && index >= 0 && index < [self.dnsServers count]) { + return self.dnsServers[index]; } return [[self defaultServers] firstObject]; } diff --git a/MSDKDns/CacheManager/MSDKDnsNetworkManager.m b/MSDKDns/CacheManager/MSDKDnsNetworkManager.m index 8d2580b..92532c7 100644 --- a/MSDKDns/CacheManager/MSDKDnsNetworkManager.m +++ b/MSDKDns/CacheManager/MSDKDnsNetworkManager.m @@ -81,7 +81,7 @@ - (instancetype)init [[MSDKDnsManager shareInstance] switchToMainServer]; BOOL enableDetectHostServer = [[MSDKDnsParamsManager shareInstance] msdkDnsGetEnableDetectHostServer]; - if (!enableDetectHostServer) { + if (enableDetectHostServer) { MSDKDNSLOG(@"Network did changed, detect HttpDns servers"); // 探测dnsIp [[MSDKDnsManager shareInstance] detectHttpDnsServers]; @@ -95,11 +95,13 @@ - (instancetype)init usingBlock:^(NSNotification *note) { BOOL expiredIPEnabled = [[MSDKDnsParamsManager shareInstance] msdkDnsGetExpiredIPEnabled]; - if (!expiredIPEnabled) { + BOOL persistCacheIPEnabled = [[MSDKDnsParamsManager shareInstance] msdkDnsGetPersistCacheIPEnabled]; + if (!expiredIPEnabled && !persistCacheIPEnabled) { MSDKDNSLOG(@"Application did enter background,clear MSDKDns cache"); - //进入后台时清除缓存,暂停网络监测 + //进入后台时清除缓存,排除开启了持久化缓存或者开启了使用过期缓存IP的情况 [[MSDKDnsManager shareInstance] clearAllCache]; } + //进入后台时,暂停网络监测 [self.reachability stopNotifier]; }]; @@ -114,7 +116,7 @@ - (instancetype)init [self getHostsByKeepAliveDomains]; BOOL enableDetectHostServer = [[MSDKDnsParamsManager shareInstance] msdkDnsGetEnableDetectHostServer]; - if (!enableDetectHostServer) { + if (enableDetectHostServer) { // 探测dnsIp [[MSDKDnsManager shareInstance] detectHttpDnsServers]; } diff --git a/MSDKDns/CacheManager/MSDKDnsParamsManager.m b/MSDKDns/CacheManager/MSDKDnsParamsManager.m index 5487e72..5153fc4 100644 --- a/MSDKDns/CacheManager/MSDKDnsParamsManager.m +++ b/MSDKDns/CacheManager/MSDKDnsParamsManager.m @@ -63,6 +63,7 @@ - (id) init { _msdkAddressType = HttpDnsAddressTypeAuto; _enableKeepDomainsAlive = YES; _expiredIPEnabled = NO; + _persistCacheIPEnabled = NO; _enableDetectHostServer = NO; } return self; diff --git a/MSDKDns/MSDKDns.h b/MSDKDns/MSDKDns.h index 5b2d547..89b4b41 100644 --- a/MSDKDns/MSDKDns.h +++ b/MSDKDns/MSDKDns.h @@ -5,7 +5,7 @@ #ifndef __MSDKDns_H__ #define __MSDKDns_H__ -#define MSDKDns_Version @"1.8.0" +#define MSDKDns_Version @"1.8.1" #import <Foundation/Foundation.h> diff --git a/MSDKDns/Resolver/HttpsDnsResolver.m b/MSDKDns/Resolver/HttpsDnsResolver.m index be55da8..2ab0439 100644 --- a/MSDKDns/Resolver/HttpsDnsResolver.m +++ b/MSDKDns/Resolver/HttpsDnsResolver.m @@ -43,7 +43,7 @@ - (void)startWithDomains:(NSArray *)domains TimeOut:(float)timeOut DnsId:(int)dn id<MSDKDnsResolverDelegate> delegate = self.delegate; self.errorCode = MSDKDns_UnResolve; if (!domainStr || domainStr.length == 0) { - MSDKDNSLOG(@"HttpDns Domain is must needed!"); + MSDKDNSLOG(@"HttpDns Domain is must needed!"); self.domainInfo = nil; self.isFinished = YES; self.isSucceed = NO; @@ -266,6 +266,10 @@ - (NSDictionary *)parseAllIPString:(NSString *)iPstring { } } + // 当双栈解析请求中ipv4和ipv6的结果都不符合预期,就返回ni走getDomainError逻辑 + if (bothIPDict.count == 0){ + return nil; + } return bothIPDict; } else { BOOL use4A = false;