Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix - #521 #522

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion YTKNetwork.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "YTKNetwork"
s.version = "3.0.0"
s.version = "3.0.2"
s.summary = "YTKNetwork is a high level request util based on AFNetworking."
s.homepage = "https://github.com/yuantiku/YTKNetwork"
s.license = "MIT"
Expand Down
23 changes: 14 additions & 9 deletions YTKNetwork/YTKNetworkAgent.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
#import "YTKNetworkPrivate.h"
#import <pthread/pthread.h>

#if __has_include(<AFNetworking/AFHTTPSessionManager.h>)
#import <AFNetworking/AFHTTPSessionManager.h>
#if __has_include(<AFNetworking/AFURLSessionManager.h>)
#import <AFNetworking/AFURLSessionManager.h>
#else
#import <AFNetworking/AFHTTPSessionManager.h>
#import <AFNetworking/AFURLSessionManager.h>
#endif

#define Lock() pthread_mutex_lock(&_lock)
Expand All @@ -38,7 +38,7 @@
#define kYTKNetworkIncompleteDownloadFolderName @"Incomplete"

@implementation YTKNetworkAgent {
AFHTTPSessionManager *_manager;
AFURLSessionManager *_manager;
YTKNetworkConfig *_config;
AFJSONResponseSerializer *_jsonResponseSerializer;
AFXMLParserResponseSerializer *_xmlParserResponseSerialzier;
Expand All @@ -62,7 +62,7 @@ - (instancetype)init {
self = [super init];
if (self) {
_config = [YTKNetworkConfig sharedConfig];
_manager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:_config.sessionConfiguration];
_manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:_config.sessionConfiguration];
_requestsRecord = [NSMutableDictionary dictionary];
_processingQueue = dispatch_queue_create("com.yuantiku.networkagent.processing", DISPATCH_QUEUE_CONCURRENT);
_allStatusCodes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(100, 500)];
Expand All @@ -71,7 +71,12 @@ - (instancetype)init {
_manager.securityPolicy = _config.securityPolicy;
_manager.responseSerializer = [AFHTTPResponseSerializer serializer];
// Take over the status code validation
_manager.responseSerializer.acceptableStatusCodes = _allStatusCodes;
AFHTTPResponseSerializer *responseSerializer = _manager.responseSerializer;
if (responseSerializer && [responseSerializer isKindOfClass:AFHTTPResponseSerializer.class]) {
responseSerializer.acceptableStatusCodes = _allStatusCodes;
}
[self jsonResponseSerializer];
[self xmlParserResponseSerialzier];
_manager.completionQueue = _processingQueue;
[_manager setTaskDidFinishCollectingMetricsBlock:_config.collectingMetricsBlock];
}
Expand Down Expand Up @@ -608,16 +613,16 @@ - (NSURL *)incompleteDownloadTempPathForDownloadPath:(NSString *)downloadPath {

#pragma mark - Testing

- (AFHTTPSessionManager *)manager {
- (AFURLSessionManager *)manager {
return _manager;
}

- (void)resetURLSessionManager {
_manager = [AFHTTPSessionManager manager];
_manager = [AFURLSessionManager init];
}

- (void)resetURLSessionManagerWithConfiguration:(NSURLSessionConfiguration *)configuration {
_manager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:configuration];
_manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
}

@end