Skip to content

Commit

Permalink
fix #7
Browse files Browse the repository at this point in the history
  • Loading branch information
bawn committed Feb 17, 2016
1 parent e7ab642 commit 0624a93
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion LCNetwork.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "LCNetwork"
s.version = "1.2.0"
s.version = "1.1.4"
s.summary = "基于AFNetworking的网络库封装"
s.homepage = "https://github.com/bawn/LCNetwork"
s.license = 'MIT'
Expand Down
8 changes: 8 additions & 0 deletions LCNetwork/LCBaseRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ typedef NS_ENUM(NSInteger , LCRequestSerializerType) {
- (BOOL)removesKeysWithNullValues;


/**
* 添加请求 Header,比如返回@{@"Accept" : @"application/json"},那么 application/json 对应的是 Value,Accept对应的是 HTTPHeaderField
*
* @return NSDictionary
*/
- (NSDictionary *)requestHeaderValue;


@end


Expand Down
11 changes: 9 additions & 2 deletions LCNetwork/LCNetworkAgent.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ - (void)addRequest:(LCBaseRequest <LCAPIRequest>*)request {
serializer.removesKeysWithNullValues = [request.child removesKeysWithNullValues];
}
self.manager.responseSerializer = serializer;

NSDictionary *argument = request.requestArgument;
// 检查是否有统一的参数加工
if (self.config.processRule && [self.config.processRule respondsToSelector:@selector(processArgumentWithRequest:query:)]) {
Expand All @@ -92,6 +91,14 @@ - (void)addRequest:(LCBaseRequest <LCAPIRequest>*)request {
self.manager.requestSerializer = [AFJSONRequestSerializer serializer];
}
}
if ([request.child respondsToSelector:@selector(requestHeaderValue)]) {
NSDictionary<NSString *, NSString *> *headerValue = [request.child requestHeaderValue];
if ([headerValue isKindOfClass:[NSDictionary class]]){
[headerValue enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSString * _Nonnull obj, BOOL * _Nonnull stop) {
[self.manager.requestSerializer setValue:obj forHTTPHeaderField:key];
}];
}
}

if ([request.child requestMethod] == LCRequestMethodGet) {
request.sessionDataTask = [self.manager GET:url parameters:argument progress:^(NSProgress * _Nonnull downloadProgress) {
Expand All @@ -104,7 +111,7 @@ - (void)addRequest:(LCBaseRequest <LCAPIRequest>*)request {
}];
}
else if ([request.child requestMethod] == LCRequestMethodPost){
// multipart `POST` request
// multipart POST request
if ([request.child respondsToSelector:@selector(constructingBodyBlock)] && [request.child constructingBodyBlock]) {

request.sessionDataTask = [self.manager POST:url parameters:argument constructingBodyWithBlock:[request.child constructingBodyBlock] progress:^(NSProgress * _Nonnull uploadProgress) {
Expand Down
2 changes: 0 additions & 2 deletions LCNetworkDemo/LCNetworkDemo/Api2.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ - (instancetype)initWith:(NSString *)lat lng:(NSString *)lng{
// };
//}



- (BOOL)cacheResponse{
return YES;
}
Expand Down
1 change: 0 additions & 1 deletion LCNetworkDemo/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ platform:ios,'7.0'
source 'https://github.com/CocoaPods/Specs.git'

pod 'AFNetworking', '~> 3.0.2'
#pod 'AFNetworkActivityLogger'
pod 'TMCache'
pod 'MBProgressHUD'

0 comments on commit 0624a93

Please sign in to comment.