Skip to content

Commit

Permalink
- Trying synchronous
Browse files Browse the repository at this point in the history
  • Loading branch information
alvincrisuy committed Aug 15, 2017
1 parent 42693aa commit 9154358
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CSFramework.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

Pod::Spec.new do |s|
s.name = 'CSFramework'
s.version = '0.1.9'
s.summary = '0.1.9'
s.version = '0.2.0'
s.summary = '0.2.0'

# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
Expand Down
1 change: 1 addition & 0 deletions CSFramework/Classes/CSRequestManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ typedef NS_ENUM(NSInteger, CSHttpMethod) {
success:(RequestSuccessBlock)successBlock
failed:(RequestFailedBlock)failedBlock
authenticated:(BOOL)authenticated
isSynchronous:(BOOL)isSynchronous
canCancelOperation:(BOOL)canCancelOperation;

// Upload Files (Array)
Expand Down
15 changes: 15 additions & 0 deletions CSFramework/Classes/CSRequestManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ - (void)request:(NSString *)URLString
success:(RequestSuccessBlock)successBlock
failed:(RequestFailedBlock)failedBlock
authenticated:(BOOL)authenticated
isSynchronous:(BOOL)isSynchronous
canCancelOperation:(BOOL)canCancelOperation {

[self initializeHTTPManagerAuthenticated:authenticated];
Expand All @@ -96,6 +97,12 @@ - (void)request:(NSString *)URLString
[self.httpManager.operationQueue cancelAllOperations];
}

__block BOOL synchronous = NO;

if (isSynchronous) {
synchronous = YES;
}

RequestProgressBlock requestProgressBlock = ^(NSProgress *progress) {

progressBlock(progress);
Expand All @@ -105,6 +112,8 @@ - (void)request:(NSString *)URLString
NSLog(@"Response Object: %@", responseObject);

successBlock(task, responseObject);

synchronous = NO;
};

RequestFailedBlock requestFailedBlock = ^(NSURLSessionDataTask *task, NSError *error) {
Expand All @@ -120,6 +129,8 @@ - (void)request:(NSString *)URLString
} else {
failedBlock(task, error);
}

synchronous = NO;
};

NSLog(LOG_API, URLString);
Expand Down Expand Up @@ -149,6 +160,10 @@ - (void)request:(NSString *)URLString
[self.httpManager DELETE:URLString parameters:parameters success:requestSuccessBlock failure:requestFailedBlock];
break;
}

if (isSynchronous) {
while (synchronous) { }
}
}

- (void)initializeURLManager {
Expand Down

0 comments on commit 9154358

Please sign in to comment.