Authored by shangjf

大数据上报接口添加https review by 枪兵

... ... @@ -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) {
... ...
... ... @@ -70,6 +70,14 @@ typedef NS_ENUM(NSInteger, YHLogStrategy) {
// 首次安装的首次启动时发送
- (void)uploadFirstLaunchAPP;
/**
是否使用HTTPS
@param enable YES表示HTTPS 开 反之 :关
*/
- (void)setHTTPSEnable:(BOOL)enable;
/**
* 用户id
*/
... ... @@ -150,4 +158,9 @@ typedef NS_ENUM(NSInteger, YHLogStrategy) {
*/
@property (copy, nonatomic) NSString *tdid;
/**
是否使用https
*/
@property (assign, nonatomic, readonly) BOOL httpsEnable;
@end
... ...
... ... @@ -58,6 +58,8 @@
// */
//@property (strong, nonatomic) YHError *error;
@property (assign, nonatomic, readwrite) BOOL httpsEnable;
- (NSString *)timestamp;
- (void)registerCrashReporter;
... ... @@ -386,4 +388,9 @@
[[YHAssemblyAssistant sharedInstance] setTDID:tdid];
}
- (void)setHTTPSEnable:(BOOL)enable
{
_httpsEnable = enable;
}
@end
... ...