Skip to content

Commit

Permalink
1.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
bawn committed Jan 4, 2017
1 parent 16f55af commit 00a20e8
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 15 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.3.2"
s.version = "1.3.3"
s.summary = "基于AFNetworking的网络库封装"
s.homepage = "https://github.com/bawn/LCNetwork"
s.license = 'MIT'
Expand Down
33 changes: 32 additions & 1 deletion LCNetwork/LCBaseRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
typedef void (^AFConstructingBlock)(id<AFMultipartFormData> formData);
typedef void (^LCRequestCompletionBlock)(__kindof LCBaseRequest *request);
typedef void (^LCRequestFailureBlock)(__kindof LCBaseRequest *request, NSError *error);
typedef void (^LCRequestFinishedBlock)(__kindof LCBaseRequest *request, NSError *error);

typedef NS_ENUM(NSInteger , LCRequestMethod) {
LCRequestMethodGet = 0,
Expand Down Expand Up @@ -170,7 +171,8 @@ typedef NS_ENUM(NSInteger , LCRequestSerializerType) {

@optional

- (void)requestFinished:(LCBaseRequest *)request;
- (void)requestSuccess:(LCBaseRequest *)request;
- (void)requestFinished:(LCBaseRequest *)request error:(NSError *)error;
- (void)requestFailed:(LCBaseRequest *)request error:(NSError *)error;
- (void)requestProgress:(NSProgress *)progress;

Expand Down Expand Up @@ -215,6 +217,7 @@ typedef NS_ENUM(NSInteger , LCRequestSerializerType) {
@property (nonatomic, strong, readonly) NSMutableArray *requestAccessories;
@property (nonatomic, copy) void (^successCompletionBlock)(LCBaseRequest *);
@property (nonatomic, copy) void (^failureCompletionBlock)(LCBaseRequest *, NSError *error);
@property (nonatomic, copy) void (^finishedCompletionBlock)(LCBaseRequest *, NSError *error);
@property (nonatomic, copy) void (^progressBlock)(NSProgress * progress);

/**
Expand Down Expand Up @@ -248,6 +251,19 @@ typedef NS_ENUM(NSInteger , LCRequestSerializerType) {
failure:(LCRequestFailureBlock)failure;


/**
block回调方式
@param success 成功回调
@param failure 失败回调
@param finished 请求完成后的回调
*/
- (void)startWithBlockSuccess:(LCRequestCompletionBlock)success
failure:(LCRequestFailureBlock)failure
finished:(LCRequestFinishedBlock)finished;



/**
* block回调方式
*
Expand All @@ -259,6 +275,21 @@ typedef NS_ENUM(NSInteger , LCRequestSerializerType) {
success:(LCRequestCompletionBlock)success
failure:(LCRequestFailureBlock)failure;


/**
block回调方式
@param progress 进度回调
@param success 成功回调
@param failure 失败回调
@param finished 请求完成后的回调
*/
- (void)startWithBlockProgress:(void (^)(NSProgress *progress))progress
success:(LCRequestCompletionBlock)success
failure:(LCRequestFailureBlock)failure
finished:(LCRequestFinishedBlock)finished;


/**
* 一般用于显示和隐藏 HUD
*
Expand Down
21 changes: 21 additions & 0 deletions LCNetwork/LCBaseRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ - (void)startWithBlockProgress:(void (^)(NSProgress *))progress
}


- (void)startWithBlockSuccess:(LCRequestCompletionBlock)success
failure:(LCRequestFailureBlock)failure
finished:(LCRequestFinishedBlock)finished{
self.successCompletionBlock = success;
self.failureCompletionBlock = failure;
self.finishedCompletionBlock = finished;
[self start];
}

- (void)startWithBlockProgress:(void (^)(NSProgress *))progress
success:(LCRequestCompletionBlock)success
failure:(LCRequestFailureBlock)failure
finished:(LCRequestFinishedBlock)finished{
self.progressBlock = progress;
self.successCompletionBlock = success;
self.failureCompletionBlock = failure;
self.finishedCompletionBlock = finished;
[self start];
}

- (id)responseJSONObject{
id responseJSONObject = nil;
// 统一加工response
Expand Down Expand Up @@ -158,6 +178,7 @@ - (void)stop{
- (void)clearCompletionBlock {
self.successCompletionBlock = nil;
self.failureCompletionBlock = nil;
self.finishedCompletionBlock = nil;
self.progressBlock = nil;
}

Expand Down
12 changes: 12 additions & 0 deletions LCNetwork/LCBatchRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
@property (nonatomic, strong, readonly) NSArray *requestArray;
@property (nonatomic, copy) void (^successCompletionBlock)(LCBatchRequest *);
@property (nonatomic, copy) void (^failureCompletionBlock)(LCBatchRequest *);
@property (nonatomic, copy) void (^finishedCompletionBlock)(LCBatchRequest *);
@property (nonatomic, weak) id<LCBatchRequestDelegate> delegate;


Expand Down Expand Up @@ -81,6 +82,17 @@ DEPRECATED_MSG_ATTRIBUTE("使用 - (void)startWithBlockSuccess:(void (^)(id requ
- (void)startWithBlockSuccess:(void (^)(LCBatchRequest *request))success
failure:(void (^)(LCBatchRequest *request))failure;

/**
* block回调方式
*
* @param success 成功回调
* @param failure 失败回调
* @param finished 请求完成后的回调
*/
- (void)startWithBlockSuccess:(void (^)(LCBatchRequest *request))success
failure:(void (^)(LCBatchRequest *request))failure
finished:(void (^)(LCBatchRequest *request))finished;



- (void)clearCompletionBlock;
Expand Down
25 changes: 21 additions & 4 deletions LCNetwork/LCBatchRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,35 @@ - (void)requestDidStop{

- (void)startWithCompletionBlockWithSuccess:(void (^)(LCBatchRequest *request))success
failure:(void (^)(LCBatchRequest *request))failure {
[self setCompletionBlockWithSuccess:success failure:failure];
[self setCompletionBlockWithSuccess:success failure:failure finished:NULL];
[self start];
}

- (void)startWithBlockSuccess:(void (^)(LCBatchRequest *request))success
failure:(void (^)(LCBatchRequest *request))failure{
[self setCompletionBlockWithSuccess:success failure:failure];
[self setCompletionBlockWithSuccess:success failure:failure finished:NULL];
[self start];
}

- (void)startWithBlockSuccess:(void (^)(LCBatchRequest *request))success
failure:(void (^)(LCBatchRequest *request))failure
finished:(void (^)(LCBatchRequest *request))finished{
[self setCompletionBlockWithSuccess:success failure:failure finished:finished];
[self start];
}

- (void)setCompletionBlockWithSuccess:(void (^)(LCBatchRequest *batchRequest))success
failure:(void (^)(LCBatchRequest *batchRequest))failure {
failure:(void (^)(LCBatchRequest *batchRequest))failure
finished:(void (^)(LCBatchRequest *batchRequest))finished{
self.successCompletionBlock = success;
self.failureCompletionBlock = failure;
self.finishedCompletionBlock = finished;
}

- (void)clearCompletionBlock {
self.successCompletionBlock = nil;
self.failureCompletionBlock = nil;
self.finishedCompletionBlock = nil;
}


Expand All @@ -116,7 +126,8 @@ - (void)dealloc {

#pragma mark - Network Request Delegate

- (void)requestFinished:(LCBaseRequest *)request {

- (void)requestSuccess:(LCBaseRequest *)request{
_finishedCount++;
if (_finishedCount == _requestArray.count) {
[self toggleAccessoriesWillStopCallBack];
Expand All @@ -126,6 +137,9 @@ - (void)requestFinished:(LCBaseRequest *)request {
if (_successCompletionBlock) {
_successCompletionBlock(self);
}
if (_finishedCompletionBlock) {
_finishedCompletionBlock(self);
}
[self requestDidStop];
}
}
Expand All @@ -141,6 +155,9 @@ - (void)requestFailed:(LCBaseRequest *)request error:(NSError *)error{
if (_failureCompletionBlock) {
_failureCompletionBlock(self);
}
if (_finishedCompletionBlock) {
_finishedCompletionBlock(self);
}
[self requestDidStop];
}

Expand Down
15 changes: 14 additions & 1 deletion LCNetwork/LCChainRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,20 @@ - (void)dealloc{

#pragma mark - Network Request Delegate

- (void)requestFinished:(LCBaseRequest *)request {
//- (void)requestFinished:(LCBaseRequest *)request {
// NSUInteger currentRequestIndex = _nextRequestIndex - 1;
// LCChainCallback callback = _requestCallbackArray[currentRequestIndex];
// callback(self, request);
// if ([self startNextRequest] == NO) {
// [self toggleAccessoriesWillStopCallBack];
// if ([_delegate respondsToSelector:@selector(chainRequestFinished:)]) {
// [_delegate chainRequestFinished:self];
// }
// [self requestDidStop];
// }
//}

- (void)requestSuccess:(LCBaseRequest *)request{
NSUInteger currentRequestIndex = _nextRequestIndex - 1;
LCChainCallback callback = _requestCallbackArray[currentRequestIndex];
callback(self, request);
Expand Down
19 changes: 15 additions & 4 deletions LCNetwork/LCNetworkAgent.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,19 @@ - (void)handleRequestSuccess:(NSURLSessionDataTask *)sessionDataTask{
[[[TMCache sharedCache] diskCache] setObject:request.responseJSONObject forKey:request.urlString];
}

if (request.delegate != nil) {
[request.delegate requestFinished:request];
if (request.delegate != nil && [request.delegate respondsToSelector:@selector(requestSuccess:)]) {
[request.delegate requestSuccess:request];
}
if (request.delegate != nil && [request.delegate respondsToSelector:@selector(requestFinished:error:)]) {
[request.delegate requestFinished:request error:nil];
}
if (request.successCompletionBlock) {
request.successCompletionBlock(request);
}
if (request.finishedCompletionBlock) {
request.finishedCompletionBlock(request, nil);
}
[request toggleAccessoriesDidStopCallBack];

}

[self removeOperation:sessionDataTask];
Expand All @@ -234,12 +239,18 @@ - (void)handleRequestFailure:(NSURLSessionDataTask *)sessionDataTask error:(NSEr
LCBaseRequest *request = _requestsRecord[key];
if (request) {
[request toggleAccessoriesWillStopCallBack];
if (request.delegate != nil) {
if (request.delegate != nil && [request.delegate respondsToSelector:@selector(requestFailed:error:)]) {
[request.delegate requestFailed:request error:error];
}
if (request.delegate != nil && [request.delegate respondsToSelector:@selector(requestFinished:error:)]) {
[request.delegate requestFinished:request error:error];
}
if (request.failureCompletionBlock) {
request.failureCompletionBlock(request, error);
}
if (request.finishedCompletionBlock) {
request.finishedCompletionBlock(request, error);
}
[request toggleAccessoriesDidStopCallBack];
}
[self removeOperation:sessionDataTask];
Expand Down
2 changes: 1 addition & 1 deletion LCNetwork/LCQueueRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ - (void)allComplete:(void (^)())block{

#pragma mark - Network Request Delegate

- (void)requestFinished:(LCBaseRequest *)request {
- (void)requestSuccess:(LCBaseRequest *)request {
dispatch_group_leave(queueRequest_request_operation_completion_group());
[[LCQueueRequestAgent sharedInstance] removeRequest:self];
}
Expand Down
10 changes: 7 additions & 3 deletions LCNetworkDemo/LCNetworkDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
7A83F2961B3C00D500DA3282 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0710;
LastUpgradeCheck = 0820;
ORGANIZATIONNAME = beike;
TargetAttributes = {
7A83F29D1B3C00D500DA3282 = {
Expand Down Expand Up @@ -455,8 +455,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -479,7 +481,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand All @@ -499,8 +501,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -516,7 +520,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
Expand Down

0 comments on commit 00a20e8

Please sign in to comment.