diff --git a/Ifish.xcodeproj/project.pbxproj b/Ifish.xcodeproj/project.pbxproj index 2f12ed4..400e6e9 100644 --- a/Ifish.xcodeproj/project.pbxproj +++ b/Ifish.xcodeproj/project.pbxproj @@ -2305,6 +2305,7 @@ C0D3A12C2647ED99008E6FD6 /* UIView+Sizes.h in Headers */ = {isa = PBXBuildFile; fileRef = C0D3A12A2647ED99008E6FD6 /* UIView+Sizes.h */; }; C0D3A12D2647ED99008E6FD6 /* UIView+Sizes.m in Sources */ = {isa = PBXBuildFile; fileRef = C0D3A12B2647ED99008E6FD6 /* UIView+Sizes.m */; }; C0D3A12F2647EDA5008E6FD6 /* ELPCircleRotateImageAsset.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C0D3A12E2647EDA5008E6FD6 /* ELPCircleRotateImageAsset.xcassets */; }; + C0D451D727955E8200609928 /* Define.m in Sources */ = {isa = PBXBuildFile; fileRef = C0D451D627955E8200609928 /* Define.m */; }; C0E746D5239E4A7D001BCD6D /* wechatlogin.png in Resources */ = {isa = PBXBuildFile; fileRef = C0E746D4239E4A7C001BCD6D /* wechatlogin.png */; }; C0E7D6C023A1D11500256A10 /* WXApiRequestHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = C0E7D6BC23A1D11200256A10 /* WXApiRequestHandler.h */; }; C0E7D6C123A1D11500256A10 /* WXApiManager.h in Headers */ = {isa = PBXBuildFile; fileRef = C0E7D6BD23A1D11200256A10 /* WXApiManager.h */; }; @@ -5784,6 +5785,7 @@ C0D3A12A2647ED99008E6FD6 /* UIView+Sizes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Sizes.h"; sourceTree = ""; }; C0D3A12B2647ED99008E6FD6 /* UIView+Sizes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+Sizes.m"; sourceTree = ""; }; C0D3A12E2647EDA5008E6FD6 /* ELPCircleRotateImageAsset.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = ELPCircleRotateImageAsset.xcassets; sourceTree = ""; }; + C0D451D627955E8200609928 /* Define.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Define.m; sourceTree = ""; }; C0E746D4239E4A7C001BCD6D /* wechatlogin.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = wechatlogin.png; sourceTree = ""; }; C0E7D6BC23A1D11200256A10 /* WXApiRequestHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXApiRequestHandler.h; sourceTree = ""; }; C0E7D6BD23A1D11200256A10 /* WXApiManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXApiManager.h; sourceTree = ""; }; @@ -10063,6 +10065,7 @@ 883E791E1D48ACFF0030E075 /* dataUnity */, 883E79211D48ACFF0030E075 /* DB */, 883E79261D48ACFF0030E075 /* Define.h */, + C0D451D627955E8200609928 /* Define.m */, 883E79341D48ACFF0030E075 /* service.html */, 883E79381D48ACFF0030E075 /* wifi_error.html */, 88742C461D645CE70074F1F8 /* shopCertification.html */, @@ -15584,6 +15587,7 @@ 881672151EA5DE2B00BEBF23 /* UMComSimpleCommentEditView.m in Sources */, 8868FE561E66C8BC002F7F33 /* DengJiShuoMingViewTopCell.m in Sources */, 88F5EFB91D48D08100CC7CAF /* UIWebView+AFNetworking.m in Sources */, + C0D451D727955E8200609928 /* Define.m in Sources */, 8867F5B41E654DFD00AF021C /* DengJiView0Cell.m in Sources */, 883E785A1D48A5E50030E075 /* XuToLightModel.m in Sources */, 883E785E1D48A5E50030E075 /* CenterViewController.m in Sources */, diff --git a/Ifish/AppDelegate.m b/Ifish/AppDelegate.m index d49dcfd..310e7d0 100644 --- a/Ifish/AppDelegate.m +++ b/Ifish/AppDelegate.m @@ -88,7 +88,7 @@ #import "IfishADTimerViewController.h" #import "AvoidCrash.h" #import - +#import @interface AppDelegate () @property(nonatomic,strong)ICSDrawerController*ics; @@ -389,56 +389,113 @@ if (kScreenSize.height>480) { -(void)setupHTTPDNS { - HttpDnsService *httpdns = [[HttpDnsService alloc] initWithAccountID:HTTPDNS_ACCOUNTID]; - - // 为HTTPDNS服务设置降级机制 - [httpdns setDelegateForDegradationFilter:self]; - // 允许返回过期的IP - [httpdns setExpiredIPEnabled:YES]; - // 打开HTTPDNS Log,线上建议关闭 - [httpdns setLogEnabled:YES]; - [httpdns setLogHandler:self]; - /* - * 设置HTTPDNS域名解析请求类型(HTTP/HTTPS),若不调用该接口,默认为HTTP请求; - * SDK内部HTTP请求基于CFNetwork实现,不受ATS限制。 - */ - //[httpdns setHTTPSRequestEnabled:YES]; - // edited - NSArray *preResolveHosts = @[DOMAIN_NAME]; - // NSArray* preResolveHosts = @[@"pic1cdn.igetget.com"]; - // 设置预解析域名列表 - [httpdns setPreResolveHosts:preResolveHosts]; - [httpdns setTimeoutInterval:15]; - httpdns=[HttpDnsService sharedInstance]; - __block NSString*ip = [httpdns getIpByHostAsync:DOMAIN_NAME]; + Boolean result,bResolved; + CFHostRef hostRef; + CFArrayRef addresses = NULL; + NSMutableArray * ipsArr = [[NSMutableArray alloc] init]; + CFStringRef hostNameRef = CFStringCreateWithCString(kCFAllocatorDefault, [DOMAIN_NAME UTF8String], kCFStringEncodingASCII); + + hostRef = CFHostCreateWithName(kCFAllocatorDefault, hostNameRef); + CFAbsoluteTime start = CFAbsoluteTimeGetCurrent(); + result = CFHostStartInfoResolution(hostRef, kCFHostAddresses, NULL); + if (result == TRUE) { + addresses = CFHostGetAddressing(hostRef, &result); + } + bResolved = result == TRUE ? true : false; + + if(bResolved) + { + struct sockaddr_in* remoteAddr; + for(int i = 0; i < CFArrayGetCount(addresses); i++) + { + CFDataRef saData = (CFDataRef)CFArrayGetValueAtIndex(addresses, i); + remoteAddr = (struct sockaddr_in*)CFDataGetBytePtr(saData); + + if(remoteAddr != NULL) + { + //获取IP地址 + char ip[16]; + strcpy(ip, inet_ntoa(remoteAddr->sin_addr)); + NSString * ipStr = [NSString stringWithCString:ip encoding:NSUTF8StringEncoding]; + [ipsArr addObject:ipStr]; + } + } + } + CFAbsoluteTime end = CFAbsoluteTimeGetCurrent(); + NSLog(@"33333 === ip === %@ === time cost: %0.3fs", ipsArr,end - start); + CFRelease(hostNameRef); + CFRelease(hostRef); + + BOOL validIP=NO; + NSString*ip=[ipsArr firstObject]; if (ip.length) { - DOMAIN_NAME=ip; + NSArray*component=[ip componentsSeparatedByString:@"."]; + NSString*first = [component firstObject]; + if (first.intValue>0) + { + validIP=YES; + } } - else + if (!validIP) { - - dispatch_queue_t queue= dispatch_queue_create("dns", DISPATCH_QUEUE_CONCURRENT); - dispatch_semaphore_t sema =dispatch_semaphore_create(0); - dispatch_async(queue, ^{ - while (!ip) { - ip = [httpdns getIpByHostAsync:DOMAIN_NAME]; - if (ip) - { - dispatch_semaphore_signal(sema); - break; - } - } - }); - dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1*NSEC_PER_SEC))); + + HttpDnsService *httpdns = [[HttpDnsService alloc] initWithAccountID:HTTPDNS_ACCOUNTID secretKey:HTTPDNS_SECRET]; + + // 为HTTPDNS服务设置降级机制 + [httpdns setDelegateForDegradationFilter:self]; + // 允许返回过期的IP + [httpdns setExpiredIPEnabled:YES]; + // 打开HTTPDNS Log,线上建议关闭 + [httpdns setLogEnabled:YES]; + [httpdns setLogHandler:self]; + /* + * 设置HTTPDNS域名解析请求类型(HTTP/HTTPS),若不调用该接口,默认为HTTP请求; + * SDK内部HTTP请求基于CFNetwork实现,不受ATS限制。 + */ + //[httpdns setHTTPSRequestEnabled:YES]; + // edited + NSArray *preResolveHosts = @[DOMAIN_NAME]; + // NSArray* preResolveHosts = @[@"pic1cdn.igetget.com"]; + // 设置预解析域名列表 + [httpdns setPreResolveHosts:preResolveHosts]; + [httpdns setTimeoutInterval:15]; + httpdns=[HttpDnsService sharedInstance]; + Define* define=[Define sharedDefine]; + __block NSString*ip = [httpdns getIpByHostAsync:DOMAIN_NAME]; + if (ip.length) { - DOMAIN_NAME=ip; + define.server=ip; + + } + else + { + + dispatch_queue_t queue= dispatch_queue_create("dns", DISPATCH_QUEUE_CONCURRENT); + dispatch_semaphore_t sema =dispatch_semaphore_create(0); + dispatch_async(queue, ^{ + while (!ip) { + ip = [httpdns getIpByHostAsync:DOMAIN_NAME]; + if (ip) + { + dispatch_semaphore_signal(sema); + break; + } + } + }); + dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1*NSEC_PER_SEC))); + if (ip.length) + { + define.server=ip; + } + + } - } + } - (BOOL)shouldDegradeHTTPDNS:(NSString *)hostName; { diff --git a/Ifish/Utinitys/Define.h b/Ifish/Utinitys/Define.h index 11855b5..1829204 100644 --- a/Ifish/Utinitys/Define.h +++ b/Ifish/Utinitys/Define.h @@ -144,9 +144,9 @@ alpha:1.0] static NSString* DOMAIN_NAME =@"app.ifish7.com"; //正式环境 -#define SOCKETPORT DOMAIN_NAME -#define JIEKOUPORT [NSString stringWithFormat:@"https://%@",DOMAIN_NAME] -#define JIEKOUPORTHTTP [NSString stringWithFormat:@"https://%@",DOMAIN_NAME] +#define SOCKETPORT [Define sharedDefine].server +#define JIEKOUPORT [[Define sharedDefine] getRealSever] +#define JIEKOUPORTHTTP [[Define sharedDefine] getRealSever] //测试环境 //#define SOCKETPORT @"test.ifish7.com:9955" //#define JIEKOUPORT @"http://139.196.24.156:7080" @@ -509,3 +509,11 @@ alpha:1.0] #define Push_Message_UnReadCount [NSString stringWithFormat:@"%@/api/updateUser/userMessageNoReadCount.do",JIEKOUPORT] /*=====================add V4.9.8=======================================*/ #endif /* Define_h */ + +#import + +@interface Define : NSObject +@property (nonatomic, strong) NSString *server; ++ (Define *)sharedDefine; +-(NSString*)getRealSever; +@end diff --git a/Ifish/Utinitys/Define.m b/Ifish/Utinitys/Define.m new file mode 100644 index 0000000..65eaeb6 --- /dev/null +++ b/Ifish/Utinitys/Define.m @@ -0,0 +1,64 @@ +// +// Define.m +// Ifish +// +// Created by 祝发冬 on 2022/1/17. +// Copyright © 2022 lianlian. All rights reserved. +// + +#import "Define.h" +@implementation Define + +static Define *defi = nil; + +/// 获取单例 ++ (Define *)sharedDefine +{ + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + defi = [[super allocWithZone:NULL] init]; + }); + return defi; +} + ++(id) allocWithZone:(struct _NSZone *)zone +{ + return [Define sharedDefine] ; +} + +-(id) copyWithZone:(struct _NSZone *)zone +{ + return [Define sharedDefine] ; +} +#pragma mark - 初始化 +- (instancetype)init +{ + self = [super init]; + if (self) + { + + self.server=DOMAIN_NAME; + } + return self; +} +-(NSString*)getRealSever +{ + NSString*server=self.server; + if (![self.server isEqualToString:DOMAIN_NAME]) { + + server=[NSString stringWithFormat:@"http://%@:7080",server]; + } + else + { + server=[NSString stringWithFormat:@"https://%@",server]; + } + return server; +} +- (void)setServer:(NSString *)server +{ + if (server.length) + { + _server=server; + } +} +@end