接口错误类型可通过自定义的url接口上报 review by 小熊
Showing
5 changed files
with
38 additions
and
7 deletions
@@ -16,7 +16,7 @@ | @@ -16,7 +16,7 @@ | ||
16 | failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure | 16 | failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure |
17 | { | 17 | { |
18 | NSError *serializationError = nil; | 18 | NSError *serializationError = nil; |
19 | - NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:&serializationError]; | 19 | + NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:URLString parameters:parameters error:&serializationError]; |
20 | if (serializationError) { | 20 | if (serializationError) { |
21 | if (failure) { | 21 | if (failure) { |
22 | #pragma clang diagnostic push | 22 | #pragma clang diagnostic push |
@@ -411,7 +411,7 @@ static dispatch_queue_t persisting_queue() { | @@ -411,7 +411,7 @@ static dispatch_queue_t persisting_queue() { | ||
411 | [self.immediUploadItemDic removeObjectForKey:JsonKeyDataTypePerfor]; | 411 | [self.immediUploadItemDic removeObjectForKey:JsonKeyDataTypePerfor]; |
412 | [self.immediUploadItemDic setObject:[[NSMutableArray alloc]initWithObjects:error.jsonDictionary, nil] forKey:JsonKeyDataTypeErrors]; | 412 | [self.immediUploadItemDic setObject:[[NSMutableArray alloc]initWithObjects:error.jsonDictionary, nil] forKey:JsonKeyDataTypeErrors]; |
413 | 413 | ||
414 | - [[YHNetworkService sharedInstance] uploadLogData:self.immediUploadItemDic completionBlock:^(BOOL success, NSError *error) { | 414 | + [[YHNetworkService sharedInstance] uploadLogcustomURL:kURLAnalyticsService2 parameters:self.immediUploadItemDic completionBlock:^(BOOL success, NSError *error) { |
415 | if (success) { | 415 | if (success) { |
416 | YALog(@"upload immedialite error success."); | 416 | YALog(@"upload immedialite error success."); |
417 | } else { | 417 | } else { |
@@ -19,7 +19,7 @@ typedef void (^YHNetworkReachabilityStatusBlock)(AFNetworkReachabilityStatus sta | @@ -19,7 +19,7 @@ typedef void (^YHNetworkReachabilityStatusBlock)(AFNetworkReachabilityStatus sta | ||
19 | - (void)setReachabilityStatusChangeBlock:(YHNetworkReachabilityStatusBlock)block; | 19 | - (void)setReachabilityStatusChangeBlock:(YHNetworkReachabilityStatusBlock)block; |
20 | 20 | ||
21 | - (AFHTTPRequestOperation *)uploadLogData:(NSDictionary *)parameters completionBlock:(void (^)(BOOL success, NSError *error))block; | 21 | - (AFHTTPRequestOperation *)uploadLogData:(NSDictionary *)parameters completionBlock:(void (^)(BOOL success, NSError *error))block; |
22 | - | 22 | +- (AFHTTPRequestOperation *)uploadLogcustomURL:(NSString *)url parameters:(NSDictionary *)parameters completionBlock:(void (^)(BOOL success, NSError *error))block; |
23 | - (AFHTTPRequestOperation *)getNewLogStrategy:(NSDictionary *)parameters completionBlock:(void (^)(NSDictionary *strategy, NSError *error))block; | 23 | - (AFHTTPRequestOperation *)getNewLogStrategy:(NSDictionary *)parameters completionBlock:(void (^)(NSDictionary *strategy, NSError *error))block; |
24 | 24 | ||
25 | + (void)uploadFirstLaunchApp:(NSDictionary *)parameters completionBlock:(void (^)(BOOL flag, NSError *error))block; | 25 | + (void)uploadFirstLaunchApp:(NSDictionary *)parameters completionBlock:(void (^)(BOOL flag, NSError *error))block; |
@@ -33,7 +33,7 @@ | @@ -33,7 +33,7 @@ | ||
33 | { | 33 | { |
34 | self = [super init]; | 34 | self = [super init]; |
35 | if (self) { | 35 | if (self) { |
36 | - self.httpClient = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:kURLAnalyticsService]]; | 36 | + self.httpClient = [AFHTTPRequestOperationManager manager]; |
37 | self.httpClient.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"]; | 37 | self.httpClient.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"]; |
38 | self.httpClient.securityPolicy.allowInvalidCertificates = YES; | 38 | self.httpClient.securityPolicy.allowInvalidCertificates = YES; |
39 | self.httpClient.operationQueue.maxConcurrentOperationCount = 6; | 39 | self.httpClient.operationQueue.maxConcurrentOperationCount = 6; |
@@ -78,7 +78,37 @@ | @@ -78,7 +78,37 @@ | ||
78 | NSString *parsJsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; | 78 | NSString *parsJsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; |
79 | NSDictionary *newParameters = @{@"_mlogs": kSafeValue(parsJsonStr)}; | 79 | NSDictionary *newParameters = @{@"_mlogs": kSafeValue(parsJsonStr)}; |
80 | 80 | ||
81 | - return [self.httpClient POST:kYASApiMethodUploadData priority:NSOperationQueuePriorityLow parameters:newParameters success:^(AFHTTPRequestOperation *operation, id responseObject) { | 81 | + return [self.httpClient POST:kURLAnalyticsService priority:NSOperationQueuePriorityLow parameters:newParameters success:^(AFHTTPRequestOperation *operation, id responseObject) { |
82 | + | ||
83 | + if (block) { | ||
84 | + block(YES, nil); | ||
85 | + } | ||
86 | + } failure:^(AFHTTPRequestOperation *operation, NSError *error) { | ||
87 | + if (block) { | ||
88 | + block(NO, error); | ||
89 | + } | ||
90 | + }]; | ||
91 | +} | ||
92 | + | ||
93 | +- (AFHTTPRequestOperation *)uploadLogcustomURL:(NSString *)url parameters:(NSDictionary *)parameters completionBlock:(void (^)(BOOL success, NSError *error))block | ||
94 | +{ | ||
95 | + NSError *error = nil; | ||
96 | + NSMutableDictionary *actualParameters = [NSMutableDictionary dictionaryWithDictionary:parameters]; | ||
97 | + | ||
98 | + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:actualParameters options:0 error:&error]; | ||
99 | + if (error) { | ||
100 | + YALog(@"json parsing, connot convert to json for: %@\n code: %ld\n reason: %@", actualParameters, (long)[error code], [error localizedDescription]); | ||
101 | + | ||
102 | + if (block) { | ||
103 | + block(NO, error); | ||
104 | + } | ||
105 | + return nil; | ||
106 | + } | ||
107 | + | ||
108 | + NSString *parsJsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; | ||
109 | + NSDictionary *newParameters = @{@"_mlogs": kSafeValue(parsJsonStr)}; | ||
110 | + | ||
111 | + return [self.httpClient POST:url priority:NSOperationQueuePriorityLow parameters:newParameters success:^(AFHTTPRequestOperation *operation, id responseObject) { | ||
82 | 112 | ||
83 | if (block) { | 113 | if (block) { |
84 | block(YES, nil); | 114 | block(YES, nil); |
@@ -44,9 +44,10 @@ | @@ -44,9 +44,10 @@ | ||
44 | 44 | ||
45 | /********* Service and Interface *********/ | 45 | /********* Service and Interface *********/ |
46 | 46 | ||
47 | -#define kURLAnalyticsService @"http://analytics.yhurl.com/" // 数据分析服务器 | 47 | +#define kURLAnalyticsService @"http://analytics.yhurl.com/yas_mobile" // 数据分析服务器 |
48 | + | ||
49 | +#define kURLAnalyticsService2 @"http://error-report.yoho.cn/ios_report.do" //接口错误上报服务器 | ||
48 | 50 | ||
49 | -#define kYASApiMethodUploadData @"yas_mobile" // 上传监测数据接口 | ||
50 | #define kYASApiMethodGetNewStrategy @"" // 获取新发送策略,接口名未定 | 51 | #define kYASApiMethodGetNewStrategy @"" // 获取新发送策略,接口名未定 |
51 | 52 | ||
52 | #if defined TESTENV | 53 | #if defined TESTENV |
-
Please register or login to post a comment