Authored by 王钱钧

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

... ... @@ -74,6 +74,7 @@
E7B8DE571A8343D200102CC4 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7B8DE561A8343D200102CC4 /* CoreLocation.framework */; };
E7B8DE5E1A836F8700102CC4 /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7B8DE5D1A836F8700102CC4 /* CoreTelephony.framework */; };
E7B8DE621A838EC200102CC4 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7B8DE611A838EC200102CC4 /* AdSupport.framework */; };
E7E3A1871BF098DA006A9266 /* AFHTTPRequestOperationManager+YHPriorityRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E7E3A1861BF098DA006A9266 /* AFHTTPRequestOperationManager+YHPriorityRequest.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
... ... @@ -226,6 +227,8 @@
E7B8DE5A1A83551300102CC4 /* YH_Analytics.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = YH_Analytics.entitlements; sourceTree = "<group>"; };
E7B8DE5D1A836F8700102CC4 /* CoreTelephony.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreTelephony.framework; path = System/Library/Frameworks/CoreTelephony.framework; sourceTree = SDKROOT; };
E7B8DE611A838EC200102CC4 /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; };
E7E3A1851BF098DA006A9266 /* AFHTTPRequestOperationManager+YHPriorityRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "AFHTTPRequestOperationManager+YHPriorityRequest.h"; sourceTree = "<group>"; };
E7E3A1861BF098DA006A9266 /* AFHTTPRequestOperationManager+YHPriorityRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "AFHTTPRequestOperationManager+YHPriorityRequest.m"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
... ... @@ -517,6 +520,8 @@
E7ADAE5A1AB95BC800C9DD0B /* YHAssemblyAssistant.m */,
CA5FDA281AEE302F00F86398 /* YHNetworkService.h */,
CA5FDA291AEE302F00F86398 /* YHNetworkService.m */,
E7E3A1851BF098DA006A9266 /* AFHTTPRequestOperationManager+YHPriorityRequest.h */,
E7E3A1861BF098DA006A9266 /* AFHTTPRequestOperationManager+YHPriorityRequest.m */,
);
path = Utils;
sourceTree = "<group>";
... ... @@ -657,6 +662,7 @@
194EDC7C1A7F52D100421E6C /* ViewController.m in Sources */,
E74D45BC1ABA7C6300EFE12E /* UIActivityIndicatorView+AFNetworking.m in Sources */,
E74D45B21ABA7C6300EFE12E /* AFHTTPRequestOperation.m in Sources */,
E7E3A1871BF098DA006A9266 /* AFHTTPRequestOperationManager+YHPriorityRequest.m in Sources */,
E74D45B91ABA7C6300EFE12E /* AFURLResponseSerialization.m in Sources */,
E7B8DE221A81D68600102CC4 /* NSString+YHAnalytics.m in Sources */,
E74D45BF1ABA7C6300EFE12E /* UIImageView+AFNetworking.m in Sources */,
... ...
//
// AFHTTPRequestOperationManager+YHPriorityRequest.h
// YH_Analytics
//
// Created by 王钱钧 on 15/11/9.
// Copyright © 2015年 YOHO. All rights reserved.
//
#import "AFHTTPRequestOperationManager.h"
@interface AFHTTPRequestOperationManager (YHPriorityRequest)
- (AFHTTPRequestOperation *)POST:(NSString *)URLString
priority:(NSOperationQueuePriority)queuePriority
parameters:(id)parameters
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure;
@end
... ...
//
// AFHTTPRequestOperationManager+YHPriorityRequest.m
// YH_Analytics
//
// Created by 王钱钧 on 15/11/9.
// Copyright © 2015年 YOHO. All rights reserved.
//
#import "AFHTTPRequestOperationManager+YHPriorityRequest.h"
@implementation AFHTTPRequestOperationManager (YHPriorityRequest)
- (AFHTTPRequestOperation *)POST:(NSString *)URLString
priority:(NSOperationQueuePriority)queuePriority
parameters:(id)parameters
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
{
NSError *serializationError = nil;
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:&serializationError];
if (serializationError) {
if (failure) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu"
dispatch_async(self.completionQueue ?: dispatch_get_main_queue(), ^{
failure(nil, serializationError);
});
#pragma clang diagnostic pop
}
return nil;
}
AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure];
[operation setQueuePriority:queuePriority]; // 设置请求优先级为最低
[self.operationQueue addOperation:operation];
return operation;
}
@end
... ...
... ... @@ -8,6 +8,7 @@
#import <Foundation/Foundation.h>
#import "AFNetworking.h"
#import "AFHTTPRequestOperationManager+YHPriorityRequest.h"
typedef void (^YHNetworkReachabilityStatusBlock)(AFNetworkReachabilityStatus status);
... ...
... ... @@ -78,7 +78,7 @@
NSString *parsJsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSDictionary *newParameters = @{@"_mlogs": kSafeValue(parsJsonStr)};
return [self.httpClient POST:kYASApiMethodUploadData parameters:newParameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
return [self.httpClient POST:kYASApiMethodUploadData priority:NSOperationQueuePriorityLow parameters:newParameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
if (block) {
block(YES, nil);
... ...