Skip to content
This repository has been archived by the owner on Feb 19, 2020. It is now read-only.

Commit

Permalink
Merge pull request #441 from bmourat/remove-nsurlconnection
Browse files Browse the repository at this point in the history
NSURLConnection removed
  • Loading branch information
Benjamin Scholtysik (Reimold) authored Aug 3, 2017
2 parents 377ecab + 1b71957 commit cdde5d1
Show file tree
Hide file tree
Showing 19 changed files with 121 additions and 816 deletions.
77 changes: 27 additions & 50 deletions Classes/BITAuthenticator.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#import "HockeySDKPrivate.h"
#import "BITAuthenticator_Private.h"
#import "BITAuthenticationViewController.h"
#import "BITHTTPOperation.h"
#import "BITHockeyAppClient.h"
#import "BITHockeyHelper.h"
#import "BITHockeyBaseManagerPrivate.h"
Expand Down Expand Up @@ -322,29 +321,20 @@ - (void)validateWithCompletion:(void (^)(BOOL validated, NSError *))completion {
NSString *validationPath = [NSString stringWithFormat:@"api/3/apps/%@/identity/validate", self.encodedAppIdentifier];

__weak typeof(self) weakSelf = self;
if ([BITHockeyHelper isURLSessionSupported]) {
NSURLRequest *request = [self.hockeyAppClient requestWithMethod:@"GET" path:validationPath parameters:[self validationParameters]];

NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];

NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse __unused *response, NSError *innerError) {
typeof(self) strongSelf = weakSelf;

[session finishTasksAndInvalidate];

[strongSelf handleValidationResponseWithData:data error:innerError completion:completion];
}];
[task resume];
} else {
[self.hockeyAppClient getPath:validationPath
parameters:[self validationParameters]
completion:^(BITHTTPOperation __unused *operation, NSData *responseData, NSError *innerError) {
typeof(self) strongSelf = weakSelf;
[strongSelf handleValidationResponseWithData:responseData error:innerError completion:completion];
}];
}
NSURLRequest *request = [self.hockeyAppClient requestWithMethod:@"GET" path:validationPath parameters:[self validationParameters]];

NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];

NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse __unused *response, NSError *innerError) {
typeof(self) strongSelf = weakSelf;

[session finishTasksAndInvalidate];

[strongSelf handleValidationResponseWithData:data error:innerError completion:completion];
}];
[task resume];
}

- (void)handleValidationResponseWithData:(NSData *)responseData error:(NSError *)error completion:(void (^)(BOOL validated, NSError *))completion {
Expand Down Expand Up @@ -481,32 +471,19 @@ - (void)authenticationViewController:(UIViewController *) __unused viewControlle
completion:(void (^)(BOOL, NSError *))completion {

__weak typeof(self) weakSelf = self;

if ([BITHockeyHelper isURLSessionSupported]) {
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];

NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError __unused *error) {
typeof(self) strongSelf = weakSelf;
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;

[session finishTasksAndInvalidate];

[strongSelf handleAuthenticationWithResponse:httpResponse email:email data:data completion:completion];
}];
[task resume];
} else {
BITHTTPOperation *operation = [self.hockeyAppClient operationWithURLRequest:request
completion:^(BITHTTPOperation *innerOperation, NSData *responseData, NSError __unused *error) {
typeof(self) strongSelf = weakSelf;
[strongSelf handleAuthenticationWithResponse:innerOperation.response
email:email
data:responseData
completion:completion];
}];
[self.hockeyAppClient enqeueHTTPOperation:operation];
}
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];

NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError __unused *error) {
typeof(self) strongSelf = weakSelf;
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;

[session finishTasksAndInvalidate];

[strongSelf handleAuthenticationWithResponse:httpResponse email:email data:data completion:completion];
}];
[task resume];
}

- (void)authenticationViewControllerDidTapWebButton:(UIViewController *) __unused viewController {
Expand Down
64 changes: 20 additions & 44 deletions Classes/BITCrashManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -1701,51 +1701,27 @@ - (void)processUploadResultWithFilename:(NSString *)filename responseData:(NSDat
* @param xml The XML data that needs to be send to the server
*/
- (void)sendCrashReportWithFilename:(NSString *)filename xml:(NSString*)xml attachment:(BITHockeyAttachment *)attachment {
BOOL sendingWithURLSession = NO;

if ([BITHockeyHelper isURLSessionSupported]) {
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];

NSURLRequest *request = [self requestWithBoundary:kBITHockeyAppClientBoundary];
NSData *data = [self postBodyWithXML:xml attachment:attachment boundary:kBITHockeyAppClientBoundary];

if (request && data) {
__weak typeof (self) weakSelf = self;
NSURLSessionUploadTask *uploadTask = [session uploadTaskWithRequest:request
fromData:data
completionHandler:^(NSData *responseData, NSURLResponse *response, NSError *error) {
typeof (self) strongSelf = weakSelf;

[session finishTasksAndInvalidate];

NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*) response;
NSInteger statusCode = [httpResponse statusCode];
[strongSelf processUploadResultWithFilename:filename responseData:responseData statusCode:statusCode error:error];
}];

[uploadTask resume];
sendingWithURLSession = YES;
}
}

if (!sendingWithURLSession) {
NSMutableURLRequest *request = [self requestWithBoundary:kBITHockeyAppClientBoundary];

NSData *postBody = [self postBodyWithXML:xml attachment:attachment boundary:kBITHockeyAppClientBoundary];
[request setHTTPBody:postBody];

NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];

NSURLRequest *request = [self requestWithBoundary:kBITHockeyAppClientBoundary];
NSData *data = [self postBodyWithXML:xml attachment:attachment boundary:kBITHockeyAppClientBoundary];

if (request && data) {
__weak typeof (self) weakSelf = self;
BITHTTPOperation *operation = [self.hockeyAppClient
operationWithURLRequest:request
completion:^(BITHTTPOperation *innerOperation, NSData* responseData, NSError *error) {
typeof (self) strongSelf = weakSelf;

NSInteger statusCode = [innerOperation.response statusCode];
[strongSelf processUploadResultWithFilename:filename responseData:responseData statusCode:statusCode error:error];
}];

[self.hockeyAppClient enqeueHTTPOperation:operation];
NSURLSessionUploadTask *uploadTask = [session uploadTaskWithRequest:request
fromData:data
completionHandler:^(NSData *responseData, NSURLResponse *response, NSError *error) {
typeof (self) strongSelf = weakSelf;

[session finishTasksAndInvalidate];

NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*) response;
NSInteger statusCode = [httpResponse statusCode];
[strongSelf processUploadResultWithFilename:filename responseData:responseData statusCode:statusCode error:error];
}];

[uploadTask resume];
}
id strongDelegate = self.delegate;
if ([strongDelegate respondsToSelector:@selector(crashManagerWillSendCrashReport:)]) {
Expand Down
2 changes: 1 addition & 1 deletion Classes/BITCrashManagerDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
/** Invoked after sending crash reports failed
@param crashManager The `BITCrashManager` instance invoking this delegate
@param error The error returned from the NSURLConnection/NSURLSession call or `kBITCrashErrorDomain`
@param error The error returned from the NSURLSession call or `kBITCrashErrorDomain`
with reason of type `BITCrashErrorReason`.
*/
- (void)crashManager:(BITCrashManager *)crashManager didFailWithError:(NSError *)error;
Expand Down
74 changes: 27 additions & 47 deletions Classes/BITFeedbackListViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -608,31 +608,21 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
attachment.isLoading = YES;
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:(NSURL *)[NSURL URLWithString:attachment.sourceURL]];
__weak typeof (self) weakSelf = self;
if ([BITHockeyHelper isURLSessionSupported]) {
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];

NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler: ^(NSData *data, NSURLResponse __unused *response, NSError *error) {
typeof (self) strongSelf = weakSelf;

[session finishTasksAndInvalidate];

[strongSelf handleResponseForAttachment:attachment responseData:data error:error];
}];
[task resume];
}else{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[NSURLConnection sendAsynchronousRequest:request queue:self.thumbnailQueue completionHandler:^(NSURLResponse __unused *response, NSData *responseData, NSError *err) {
#pragma clang diagnostic pop
typeof (self) strongSelf = weakSelf;
[strongSelf handleResponseForAttachment:attachment responseData:responseData error:err];
}];
}
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];

NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler: ^(NSData *data, NSURLResponse __unused *response, NSError *error) {
typeof (self) strongSelf = weakSelf;

[session finishTasksAndInvalidate];

[strongSelf handleResponseForAttachment:attachment responseData:data error:error];
}];
[task resume];
}
}

if (indexPath.row != 0) {
UIView *lineView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, 1)];
lineView1.backgroundColor = BORDER_COLOR;
Expand Down Expand Up @@ -872,30 +862,20 @@ - (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *) __u
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:(NSURL *)[NSURL URLWithString:attachment.sourceURL]];

__weak typeof (self) weakSelf = self;
if ([BITHockeyHelper isURLSessionSupported]) {
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];

NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler: ^(NSData *data, NSURLResponse __unused *response, NSError __unused *error) {
dispatch_async(dispatch_get_main_queue(), ^{
typeof (self) strongSelf = weakSelf;

[session finishTasksAndInvalidate];

[strongSelf previewController:blockController updateAttachment:attachment data:data];
});
}];
[task resume];
}else{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[NSURLConnection sendAsynchronousRequest:request queue:self.thumbnailQueue completionHandler:^(NSURLResponse __unused *response, NSData *responseData, NSError __unused *err) {
#pragma clang diagnostic pop
typeof (self) strongSelf = weakSelf;
[strongSelf previewController:blockController updateAttachment:attachment data:responseData];
}];
}
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];

NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler: ^(NSData *data, NSURLResponse __unused *response, NSError __unused *error) {
dispatch_async(dispatch_get_main_queue(), ^{
typeof (self) strongSelf = weakSelf;

[session finishTasksAndInvalidate];

[strongSelf previewController:blockController updateAttachment:attachment data:data];
});
}];
[task resume];
return attachment;
} else {
return self.cachedPreviewItems[index];
Expand Down
29 changes: 9 additions & 20 deletions Classes/BITFeedbackManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -979,29 +979,18 @@ - (void)sendNetworkRequestWithHTTPMethod:(NSString *)httpMethod withMessage:(BIT
[request setHTTPBody:postBody];
}
__weak typeof(self) weakSelf = self;
if ([BITHockeyHelper isURLSessionSupported]) {
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];

NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
typeof(self) strongSelf = weakSelf;
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
typeof(self) strongSelf = weakSelf;

[session finishTasksAndInvalidate];
[session finishTasksAndInvalidate];

[strongSelf handleFeedbackMessageResponse:response data:data error:error completion:completionHandler];
}];
[task resume];

} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *responseData, NSError *error) {
#pragma clang diagnostic pop
typeof(self) strongSelf = weakSelf;
[strongSelf handleFeedbackMessageResponse:response data:responseData error:error completion:completionHandler];
}];
}
[strongSelf handleFeedbackMessageResponse:response data:data error:error completion:completionHandler];
}];
[task resume];

}

Expand Down
Loading

0 comments on commit cdde5d1

Please sign in to comment.