Authored by 王钱钧

设置实时发送数据的请求优先级为最低,防止其占用app其他请求的带宽。code review by 小熊

@@ -74,6 +74,7 @@ @@ -74,6 +74,7 @@
74 E7B8DE571A8343D200102CC4 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7B8DE561A8343D200102CC4 /* CoreLocation.framework */; }; 74 E7B8DE571A8343D200102CC4 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7B8DE561A8343D200102CC4 /* CoreLocation.framework */; };
75 E7B8DE5E1A836F8700102CC4 /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7B8DE5D1A836F8700102CC4 /* CoreTelephony.framework */; }; 75 E7B8DE5E1A836F8700102CC4 /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7B8DE5D1A836F8700102CC4 /* CoreTelephony.framework */; };
76 E7B8DE621A838EC200102CC4 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7B8DE611A838EC200102CC4 /* AdSupport.framework */; }; 76 E7B8DE621A838EC200102CC4 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7B8DE611A838EC200102CC4 /* AdSupport.framework */; };
  77 + E7E3A1871BF098DA006A9266 /* AFHTTPRequestOperationManager+YHPriorityRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E7E3A1861BF098DA006A9266 /* AFHTTPRequestOperationManager+YHPriorityRequest.m */; };
77 /* End PBXBuildFile section */ 78 /* End PBXBuildFile section */
78 79
79 /* Begin PBXContainerItemProxy section */ 80 /* Begin PBXContainerItemProxy section */
@@ -226,6 +227,8 @@ @@ -226,6 +227,8 @@
226 E7B8DE5A1A83551300102CC4 /* YH_Analytics.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = YH_Analytics.entitlements; sourceTree = "<group>"; }; 227 E7B8DE5A1A83551300102CC4 /* YH_Analytics.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = YH_Analytics.entitlements; sourceTree = "<group>"; };
227 E7B8DE5D1A836F8700102CC4 /* CoreTelephony.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreTelephony.framework; path = System/Library/Frameworks/CoreTelephony.framework; sourceTree = SDKROOT; }; 228 E7B8DE5D1A836F8700102CC4 /* CoreTelephony.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreTelephony.framework; path = System/Library/Frameworks/CoreTelephony.framework; sourceTree = SDKROOT; };
228 E7B8DE611A838EC200102CC4 /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; }; 229 E7B8DE611A838EC200102CC4 /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; };
  230 + E7E3A1851BF098DA006A9266 /* AFHTTPRequestOperationManager+YHPriorityRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "AFHTTPRequestOperationManager+YHPriorityRequest.h"; sourceTree = "<group>"; };
  231 + E7E3A1861BF098DA006A9266 /* AFHTTPRequestOperationManager+YHPriorityRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "AFHTTPRequestOperationManager+YHPriorityRequest.m"; sourceTree = "<group>"; };
229 /* End PBXFileReference section */ 232 /* End PBXFileReference section */
230 233
231 /* Begin PBXFrameworksBuildPhase section */ 234 /* Begin PBXFrameworksBuildPhase section */
@@ -517,6 +520,8 @@ @@ -517,6 +520,8 @@
517 E7ADAE5A1AB95BC800C9DD0B /* YHAssemblyAssistant.m */, 520 E7ADAE5A1AB95BC800C9DD0B /* YHAssemblyAssistant.m */,
518 CA5FDA281AEE302F00F86398 /* YHNetworkService.h */, 521 CA5FDA281AEE302F00F86398 /* YHNetworkService.h */,
519 CA5FDA291AEE302F00F86398 /* YHNetworkService.m */, 522 CA5FDA291AEE302F00F86398 /* YHNetworkService.m */,
  523 + E7E3A1851BF098DA006A9266 /* AFHTTPRequestOperationManager+YHPriorityRequest.h */,
  524 + E7E3A1861BF098DA006A9266 /* AFHTTPRequestOperationManager+YHPriorityRequest.m */,
520 ); 525 );
521 path = Utils; 526 path = Utils;
522 sourceTree = "<group>"; 527 sourceTree = "<group>";
@@ -657,6 +662,7 @@ @@ -657,6 +662,7 @@
657 194EDC7C1A7F52D100421E6C /* ViewController.m in Sources */, 662 194EDC7C1A7F52D100421E6C /* ViewController.m in Sources */,
658 E74D45BC1ABA7C6300EFE12E /* UIActivityIndicatorView+AFNetworking.m in Sources */, 663 E74D45BC1ABA7C6300EFE12E /* UIActivityIndicatorView+AFNetworking.m in Sources */,
659 E74D45B21ABA7C6300EFE12E /* AFHTTPRequestOperation.m in Sources */, 664 E74D45B21ABA7C6300EFE12E /* AFHTTPRequestOperation.m in Sources */,
  665 + E7E3A1871BF098DA006A9266 /* AFHTTPRequestOperationManager+YHPriorityRequest.m in Sources */,
660 E74D45B91ABA7C6300EFE12E /* AFURLResponseSerialization.m in Sources */, 666 E74D45B91ABA7C6300EFE12E /* AFURLResponseSerialization.m in Sources */,
661 E7B8DE221A81D68600102CC4 /* NSString+YHAnalytics.m in Sources */, 667 E7B8DE221A81D68600102CC4 /* NSString+YHAnalytics.m in Sources */,
662 E74D45BF1ABA7C6300EFE12E /* UIImageView+AFNetworking.m in Sources */, 668 E74D45BF1ABA7C6300EFE12E /* UIImageView+AFNetworking.m in Sources */,
  1 +//
  2 +// AFHTTPRequestOperationManager+YHPriorityRequest.h
  3 +// YH_Analytics
  4 +//
  5 +// Created by 王钱钧 on 15/11/9.
  6 +// Copyright © 2015年 YOHO. All rights reserved.
  7 +//
  8 +
  9 +#import "AFHTTPRequestOperationManager.h"
  10 +
  11 +@interface AFHTTPRequestOperationManager (YHPriorityRequest)
  12 +
  13 +- (AFHTTPRequestOperation *)POST:(NSString *)URLString
  14 + priority:(NSOperationQueuePriority)queuePriority
  15 + parameters:(id)parameters
  16 + success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
  17 + failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure;
  18 +@end
  1 +//
  2 +// AFHTTPRequestOperationManager+YHPriorityRequest.m
  3 +// YH_Analytics
  4 +//
  5 +// Created by 王钱钧 on 15/11/9.
  6 +// Copyright © 2015年 YOHO. All rights reserved.
  7 +//
  8 +
  9 +#import "AFHTTPRequestOperationManager+YHPriorityRequest.h"
  10 +
  11 +@implementation AFHTTPRequestOperationManager (YHPriorityRequest)
  12 +- (AFHTTPRequestOperation *)POST:(NSString *)URLString
  13 + priority:(NSOperationQueuePriority)queuePriority
  14 + parameters:(id)parameters
  15 + success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
  16 + failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
  17 +{
  18 + NSError *serializationError = nil;
  19 + NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:&serializationError];
  20 + if (serializationError) {
  21 + if (failure) {
  22 +#pragma clang diagnostic push
  23 +#pragma clang diagnostic ignored "-Wgnu"
  24 + dispatch_async(self.completionQueue ?: dispatch_get_main_queue(), ^{
  25 + failure(nil, serializationError);
  26 + });
  27 +#pragma clang diagnostic pop
  28 + }
  29 +
  30 + return nil;
  31 + }
  32 +
  33 + AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure];
  34 + [operation setQueuePriority:queuePriority]; // 设置请求优先级为最低
  35 + [self.operationQueue addOperation:operation];
  36 +
  37 + return operation;
  38 +}
  39 +
  40 +@end
@@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
8 8
9 #import <Foundation/Foundation.h> 9 #import <Foundation/Foundation.h>
10 #import "AFNetworking.h" 10 #import "AFNetworking.h"
  11 +#import "AFHTTPRequestOperationManager+YHPriorityRequest.h"
11 12
12 typedef void (^YHNetworkReachabilityStatusBlock)(AFNetworkReachabilityStatus status); 13 typedef void (^YHNetworkReachabilityStatusBlock)(AFNetworkReachabilityStatus status);
13 14
@@ -78,7 +78,7 @@ @@ -78,7 +78,7 @@
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 parameters:newParameters success:^(AFHTTPRequestOperation *operation, id responseObject) { 81 + return [self.httpClient POST:kYASApiMethodUploadData priority:NSOperationQueuePriorityLow parameters:newParameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
82 82
83 if (block) { 83 if (block) {
84 block(YES, nil); 84 block(YES, nil);