...
|
...
|
@@ -9,6 +9,9 @@ |
|
|
#import "YHNetworkService.h"
|
|
|
#import "YH_Analytics.h"
|
|
|
|
|
|
static NSString *const YH_HTTPS_PREFIX = @"https://";
|
|
|
static NSString *const YH_HTTP_PREFIX = @"http://";
|
|
|
|
|
|
@interface YHNetworkService ()
|
|
|
|
|
|
@property (strong, nonatomic) AFHTTPRequestOperationManager *httpClient;
|
...
|
...
|
@@ -57,6 +60,26 @@ |
|
|
self.httpClient = nil;
|
|
|
}
|
|
|
|
|
|
- (NSString *)checkHttpsPrefix:(NSString *)urlString
|
|
|
{
|
|
|
urlString = [self urlStringByTransformToHttpsProtocol:urlString];//进行http->https的转换
|
|
|
return urlString;
|
|
|
}
|
|
|
|
|
|
- (NSString *)urlStringByTransformToHttpsProtocol:(NSString *)originURLString
|
|
|
{
|
|
|
NSString *transformedURLString = originURLString;
|
|
|
if([YH_Analytics sharedInstance].httpsEnable){
|
|
|
NSUInteger minLen = [YH_HTTP_PREFIX length];
|
|
|
transformedURLString = [originURLString stringByReplacingOccurrencesOfString:YH_HTTP_PREFIX
|
|
|
withString:YH_HTTPS_PREFIX
|
|
|
options:NSCaseInsensitiveSearch
|
|
|
range:NSMakeRange(0, minLen)];
|
|
|
}
|
|
|
return transformedURLString;
|
|
|
}
|
|
|
|
|
|
|
|
|
#pragma mark - public method
|
|
|
|
|
|
- (void)setReachabilityStatusChangeBlock:(void (^)(AFNetworkReachabilityStatus status))block
|
...
|
...
|
@@ -85,8 +108,10 @@ |
|
|
|
|
|
NSString *parsJsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
|
NSDictionary *newParameters = @{@"_mlogs": kSafeValue(parsJsonStr)};
|
|
|
|
|
|
NSString *url = [self checkHttpsPrefix:kURLAnalyticsService];
|
|
|
|
|
|
return [self.httpClient POST:kURLAnalyticsService priority:NSOperationQueuePriorityLow parameters:newParameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
|
|
return [self.httpClient POST:url priority:NSOperationQueuePriorityLow parameters:newParameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
|
|
|
|
|
if (block) {
|
|
|
block(YES, nil);
|
...
|
...
|
@@ -190,6 +215,8 @@ |
|
|
|
|
|
NSString *parsJsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
|
NSDictionary *newParameters = @{@"_mlogs": kSafeValue(parsJsonStr)};
|
|
|
|
|
|
url = [self checkHttpsPrefix:url];
|
|
|
|
|
|
return [self.httpClient POST:url priority:NSOperationQueuePriorityLow parameters:newParameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
|
|
|
...
|
...
|
|