From 0a99af1d17d65ef17ad3e4ffb2333e60cefed9b6 Mon Sep 17 00:00:00 2001 From: tpctt Date: Thu, 25 May 2017 11:44:52 +0800 Subject: [PATCH] =?UTF-8?q?TimAFAppConnectClient=20=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=8B=86=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TimAFAppConnectClient.m | 78 ++++++++----------- 1 file changed, 34 insertions(+), 44 deletions(-) diff --git a/Classes/TimAFAppConnectClient/TimAFAppConnectClient.m b/Classes/TimAFAppConnectClient/TimAFAppConnectClient.m index 07172ea..655254b 100644 --- a/Classes/TimAFAppConnectClient/TimAFAppConnectClient.m +++ b/Classes/TimAFAppConnectClient/TimAFAppConnectClient.m @@ -30,6 +30,37 @@ +(void)setBaseUrl:(NSString*)url #pragma mark- 单例对象,实例话 ++(TimAFAppConnectClient *)appConnectClientWith:(NSString *)baseUrl +{ + TimAFAppConnectClient * shareNetworkClient22 = [[TimAFAppConnectClient alloc] initWithBaseURL:[NSURL URLWithString:baseUrl]]; + shareNetworkClient22.requestSerializer = [AFHTTPRequestSerializer serializer]; + + shareNetworkClient22.responseSerializer = [AFJSONResponseSerializer serializer]; + + shareNetworkClient22.responseSerializer.acceptableContentTypes =[NSSet setWithArray:@[@"text/html",@"text/plain",@"application/json"]]; + + shareNetworkClient22.netStateCache = [NSCache new]; + shareNetworkClient22.allShareClient = [NSCache new]; + + + + + // shareNetworkClient.requestSerializer.HTTPMethodsEncodingParametersInURI = [NSSet setWithArray:@[@"POST", @"GET", @"HEAD"]]; + + + // AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate ]; + // + // securityPolicy.pinnedCertificates = [NSSet setWithObject:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"www.taoqian123.com" ofType:@"cer"]]]; + //// securityPolicy.validatesDomainName = NO; + //// securityPolicy.allowInvalidCertificates = YES; + //// + // shareNetworkClient.securityPolicy = securityPolicy; + + + + return shareNetworkClient22; + +} +(TimAFAppConnectClient *)sharedClientFor:(NSString *)baseUrl { @@ -43,40 +74,9 @@ +(TimAFAppConnectClient *)sharedClientFor:(NSString *)baseUrl __block TimAFAppConnectClient *share = [allShare.allShareClient objectForKey:baseUrl]; if (share == nil) { + share = [TimAFAppConnectClient appConnectClientWith:baseUrl]; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - - - TimAFAppConnectClient * shareNetworkClient22 = [[TimAFAppConnectClient alloc] initWithBaseURL:[NSURL URLWithString:baseUrl]]; - shareNetworkClient22.requestSerializer = [AFHTTPRequestSerializer serializer]; - - shareNetworkClient22.responseSerializer = [AFJSONResponseSerializer serializer]; - - shareNetworkClient22.responseSerializer.acceptableContentTypes =[NSSet setWithArray:@[@"text/html",@"text/plain",@"application/json"]]; - - // shareNetworkClient.requestSerializer.HTTPMethodsEncodingParametersInURI = [NSSet setWithArray:@[@"POST", @"GET", @"HEAD"]]; - - - // AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate ]; - // - // securityPolicy.pinnedCertificates = [NSSet setWithObject:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"www.taoqian123.com" ofType:@"cer"]]]; - //// securityPolicy.validatesDomainName = NO; - //// securityPolicy.allowInvalidCertificates = YES; - //// - // shareNetworkClient.securityPolicy = securityPolicy; - - - share = shareNetworkClient22; - shareNetworkClient22 = nil; - - [allShare.allShareClient setObject:share forKey:baseUrl]; - - share.netStateCache = [NSCache new]; - - }); - - + [allShare.allShareClient setObject:share forKey:baseUrl]; } @@ -92,17 +92,7 @@ + (TimAFAppConnectClient *)sharedClient dispatch_once(&onceToken, ^{ - shareNetworkClient = [[TimAFAppConnectClient alloc] initWithBaseURL:[NSURL URLWithString:baseUrl]]; - shareNetworkClient.requestSerializer = [AFHTTPRequestSerializer serializer]; - - shareNetworkClient.responseSerializer = [AFJSONResponseSerializer serializer]; - - shareNetworkClient.responseSerializer.acceptableContentTypes =[NSSet setWithArray:@[@"text/html",@"text/plain",@"application/json"]]; - - - shareNetworkClient.allShareClient = [NSCache new]; - shareNetworkClient.netStateCache = [NSCache new]; - + shareNetworkClient = [TimAFAppConnectClient appConnectClientWith:baseUrl]; });