集成httpdns

This commit is contained in:
kai60
2022-01-17 11:40:56 +08:00
parent 7b7faab5ce
commit f63f7d216c
82 changed files with 2789 additions and 13 deletions
+72 -1
View File
@@ -53,6 +53,8 @@
#define UMCommunity_APPKEY @"569f530fe0f55a3e9a002502"
#define UMCommunity_SECRET @"462384e695d18d287ee46c423c5dce34"
#define HTTPDNS_ACCOUNTID 139960
#define HTTPDNS_SECRET @"9ff868c992944f68a2a8929bc09e9f41"
//友盟分享appkey 和社区可通用
#import "UMSocialWechatHandler.h"
@@ -85,7 +87,9 @@
#import <AlibcTradeSDK/AlibcTradeSDK.h>
#import "IfishADTimerViewController.h"
#import "AvoidCrash.h"
@interface AppDelegate ()
#import <AlicloudHttpDNS/AlicloudHttpDNS.h>
@interface AppDelegate ()<HttpDNSDegradationDelegate,HttpdnsLoggerProtocol>
@property(nonatomic,strong)ICSDrawerController*ics;
@property(nonatomic)NSString*downloadAddress;
@@ -174,6 +178,9 @@
if (data != nil) {
[self sendExceptionLogWithData:data path:dataPath];
}*/
[self setupHTTPDNS];
#ifdef __OPTIMIZE__
[AvoidCrash becomeEffective];
#endif
@@ -377,6 +384,70 @@ if (kScreenSize.height>480) {
return YES;
}
#pragma mark - mark dns解析
-(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];
if (ip.length)
{
DOMAIN_NAME=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)
{
DOMAIN_NAME=ip;
}
}
}
- (BOOL)shouldDegradeHTTPDNS:(NSString *)hostName;
{
return NO;
}
- (void)log:(NSString *)logStr;
{
NSLog(@"dnsLog:%@",logStr);
}
//自定义toast提示框
-(void)setUpToastView{