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

Commit cdde5d1

Browse files
author
Benjamin Scholtysik (Reimold)
authored
Merge pull request #441 from bmourat/remove-nsurlconnection
NSURLConnection removed
2 parents 377ecab + 1b71957 commit cdde5d1

19 files changed

+121
-816
lines changed

Classes/BITAuthenticator.m

Lines changed: 27 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#import "HockeySDKPrivate.h"
3535
#import "BITAuthenticator_Private.h"
3636
#import "BITAuthenticationViewController.h"
37-
#import "BITHTTPOperation.h"
3837
#import "BITHockeyAppClient.h"
3938
#import "BITHockeyHelper.h"
4039
#import "BITHockeyBaseManagerPrivate.h"
@@ -322,29 +321,20 @@ - (void)validateWithCompletion:(void (^)(BOOL validated, NSError *))completion {
322321
NSString *validationPath = [NSString stringWithFormat:@"api/3/apps/%@/identity/validate", self.encodedAppIdentifier];
323322

324323
__weak typeof(self) weakSelf = self;
325-
if ([BITHockeyHelper isURLSessionSupported]) {
326-
NSURLRequest *request = [self.hockeyAppClient requestWithMethod:@"GET" path:validationPath parameters:[self validationParameters]];
327-
328-
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
329-
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
330-
331-
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
332-
completionHandler:^(NSData *data, NSURLResponse __unused *response, NSError *innerError) {
333-
typeof(self) strongSelf = weakSelf;
334-
335-
[session finishTasksAndInvalidate];
336-
337-
[strongSelf handleValidationResponseWithData:data error:innerError completion:completion];
338-
}];
339-
[task resume];
340-
} else {
341-
[self.hockeyAppClient getPath:validationPath
342-
parameters:[self validationParameters]
343-
completion:^(BITHTTPOperation __unused *operation, NSData *responseData, NSError *innerError) {
344-
typeof(self) strongSelf = weakSelf;
345-
[strongSelf handleValidationResponseWithData:responseData error:innerError completion:completion];
346-
}];
347-
}
324+
NSURLRequest *request = [self.hockeyAppClient requestWithMethod:@"GET" path:validationPath parameters:[self validationParameters]];
325+
326+
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
327+
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
328+
329+
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
330+
completionHandler:^(NSData *data, NSURLResponse __unused *response, NSError *innerError) {
331+
typeof(self) strongSelf = weakSelf;
332+
333+
[session finishTasksAndInvalidate];
334+
335+
[strongSelf handleValidationResponseWithData:data error:innerError completion:completion];
336+
}];
337+
[task resume];
348338
}
349339

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

483473
__weak typeof(self) weakSelf = self;
484-
485-
if ([BITHockeyHelper isURLSessionSupported]) {
486-
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
487-
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
488-
489-
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
490-
completionHandler:^(NSData *data, NSURLResponse *response, NSError __unused *error) {
491-
typeof(self) strongSelf = weakSelf;
492-
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
493-
494-
[session finishTasksAndInvalidate];
495-
496-
[strongSelf handleAuthenticationWithResponse:httpResponse email:email data:data completion:completion];
497-
}];
498-
[task resume];
499-
} else {
500-
BITHTTPOperation *operation = [self.hockeyAppClient operationWithURLRequest:request
501-
completion:^(BITHTTPOperation *innerOperation, NSData *responseData, NSError __unused *error) {
502-
typeof(self) strongSelf = weakSelf;
503-
[strongSelf handleAuthenticationWithResponse:innerOperation.response
504-
email:email
505-
data:responseData
506-
completion:completion];
507-
}];
508-
[self.hockeyAppClient enqeueHTTPOperation:operation];
509-
}
474+
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
475+
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
476+
477+
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
478+
completionHandler:^(NSData *data, NSURLResponse *response, NSError __unused *error) {
479+
typeof(self) strongSelf = weakSelf;
480+
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
481+
482+
[session finishTasksAndInvalidate];
483+
484+
[strongSelf handleAuthenticationWithResponse:httpResponse email:email data:data completion:completion];
485+
}];
486+
[task resume];
510487
}
511488

512489
- (void)authenticationViewControllerDidTapWebButton:(UIViewController *) __unused viewController {

Classes/BITCrashManager.m

Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,51 +1701,27 @@ - (void)processUploadResultWithFilename:(NSString *)filename responseData:(NSDat
17011701
* @param xml The XML data that needs to be send to the server
17021702
*/
17031703
- (void)sendCrashReportWithFilename:(NSString *)filename xml:(NSString*)xml attachment:(BITHockeyAttachment *)attachment {
1704-
BOOL sendingWithURLSession = NO;
1705-
1706-
if ([BITHockeyHelper isURLSessionSupported]) {
1707-
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
1708-
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
1709-
1710-
NSURLRequest *request = [self requestWithBoundary:kBITHockeyAppClientBoundary];
1711-
NSData *data = [self postBodyWithXML:xml attachment:attachment boundary:kBITHockeyAppClientBoundary];
1712-
1713-
if (request && data) {
1714-
__weak typeof (self) weakSelf = self;
1715-
NSURLSessionUploadTask *uploadTask = [session uploadTaskWithRequest:request
1716-
fromData:data
1717-
completionHandler:^(NSData *responseData, NSURLResponse *response, NSError *error) {
1718-
typeof (self) strongSelf = weakSelf;
1719-
1720-
[session finishTasksAndInvalidate];
1721-
1722-
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*) response;
1723-
NSInteger statusCode = [httpResponse statusCode];
1724-
[strongSelf processUploadResultWithFilename:filename responseData:responseData statusCode:statusCode error:error];
1725-
}];
1726-
1727-
[uploadTask resume];
1728-
sendingWithURLSession = YES;
1729-
}
1730-
}
1731-
1732-
if (!sendingWithURLSession) {
1733-
NSMutableURLRequest *request = [self requestWithBoundary:kBITHockeyAppClientBoundary];
1734-
1735-
NSData *postBody = [self postBodyWithXML:xml attachment:attachment boundary:kBITHockeyAppClientBoundary];
1736-
[request setHTTPBody:postBody];
1737-
1704+
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
1705+
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
1706+
1707+
NSURLRequest *request = [self requestWithBoundary:kBITHockeyAppClientBoundary];
1708+
NSData *data = [self postBodyWithXML:xml attachment:attachment boundary:kBITHockeyAppClientBoundary];
1709+
1710+
if (request && data) {
17381711
__weak typeof (self) weakSelf = self;
1739-
BITHTTPOperation *operation = [self.hockeyAppClient
1740-
operationWithURLRequest:request
1741-
completion:^(BITHTTPOperation *innerOperation, NSData* responseData, NSError *error) {
1742-
typeof (self) strongSelf = weakSelf;
1743-
1744-
NSInteger statusCode = [innerOperation.response statusCode];
1745-
[strongSelf processUploadResultWithFilename:filename responseData:responseData statusCode:statusCode error:error];
1746-
}];
1747-
1748-
[self.hockeyAppClient enqeueHTTPOperation:operation];
1712+
NSURLSessionUploadTask *uploadTask = [session uploadTaskWithRequest:request
1713+
fromData:data
1714+
completionHandler:^(NSData *responseData, NSURLResponse *response, NSError *error) {
1715+
typeof (self) strongSelf = weakSelf;
1716+
1717+
[session finishTasksAndInvalidate];
1718+
1719+
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*) response;
1720+
NSInteger statusCode = [httpResponse statusCode];
1721+
[strongSelf processUploadResultWithFilename:filename responseData:responseData statusCode:statusCode error:error];
1722+
}];
1723+
1724+
[uploadTask resume];
17491725
}
17501726
id strongDelegate = self.delegate;
17511727
if ([strongDelegate respondsToSelector:@selector(crashManagerWillSendCrashReport:)]) {

Classes/BITCrashManagerDelegate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
/** Invoked after sending crash reports failed
121121
122122
@param crashManager The `BITCrashManager` instance invoking this delegate
123-
@param error The error returned from the NSURLConnection/NSURLSession call or `kBITCrashErrorDomain`
123+
@param error The error returned from the NSURLSession call or `kBITCrashErrorDomain`
124124
with reason of type `BITCrashErrorReason`.
125125
*/
126126
- (void)crashManager:(BITCrashManager *)crashManager didFailWithError:(NSError *)error;

Classes/BITFeedbackListViewController.m

Lines changed: 27 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -608,31 +608,21 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
608608
attachment.isLoading = YES;
609609
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:(NSURL *)[NSURL URLWithString:attachment.sourceURL]];
610610
__weak typeof (self) weakSelf = self;
611-
if ([BITHockeyHelper isURLSessionSupported]) {
612-
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
613-
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
614-
615-
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
616-
completionHandler: ^(NSData *data, NSURLResponse __unused *response, NSError *error) {
617-
typeof (self) strongSelf = weakSelf;
618-
619-
[session finishTasksAndInvalidate];
620-
621-
[strongSelf handleResponseForAttachment:attachment responseData:data error:error];
622-
}];
623-
[task resume];
624-
}else{
625-
#pragma clang diagnostic push
626-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
627-
[NSURLConnection sendAsynchronousRequest:request queue:self.thumbnailQueue completionHandler:^(NSURLResponse __unused *response, NSData *responseData, NSError *err) {
628-
#pragma clang diagnostic pop
629-
typeof (self) strongSelf = weakSelf;
630-
[strongSelf handleResponseForAttachment:attachment responseData:responseData error:err];
631-
}];
632-
}
611+
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
612+
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
613+
614+
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
615+
completionHandler: ^(NSData *data, NSURLResponse __unused *response, NSError *error) {
616+
typeof (self) strongSelf = weakSelf;
617+
618+
[session finishTasksAndInvalidate];
619+
620+
[strongSelf handleResponseForAttachment:attachment responseData:data error:error];
621+
}];
622+
[task resume];
633623
}
634624
}
635-
625+
636626
if (indexPath.row != 0) {
637627
UIView *lineView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, 1)];
638628
lineView1.backgroundColor = BORDER_COLOR;
@@ -872,30 +862,20 @@ - (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *) __u
872862
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:(NSURL *)[NSURL URLWithString:attachment.sourceURL]];
873863

874864
__weak typeof (self) weakSelf = self;
875-
if ([BITHockeyHelper isURLSessionSupported]) {
876-
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
877-
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
878-
879-
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
880-
completionHandler: ^(NSData *data, NSURLResponse __unused *response, NSError __unused *error) {
881-
dispatch_async(dispatch_get_main_queue(), ^{
882-
typeof (self) strongSelf = weakSelf;
883-
884-
[session finishTasksAndInvalidate];
885-
886-
[strongSelf previewController:blockController updateAttachment:attachment data:data];
887-
});
888-
}];
889-
[task resume];
890-
}else{
891-
#pragma clang diagnostic push
892-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
893-
[NSURLConnection sendAsynchronousRequest:request queue:self.thumbnailQueue completionHandler:^(NSURLResponse __unused *response, NSData *responseData, NSError __unused *err) {
894-
#pragma clang diagnostic pop
895-
typeof (self) strongSelf = weakSelf;
896-
[strongSelf previewController:blockController updateAttachment:attachment data:responseData];
897-
}];
898-
}
865+
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
866+
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
867+
868+
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
869+
completionHandler: ^(NSData *data, NSURLResponse __unused *response, NSError __unused *error) {
870+
dispatch_async(dispatch_get_main_queue(), ^{
871+
typeof (self) strongSelf = weakSelf;
872+
873+
[session finishTasksAndInvalidate];
874+
875+
[strongSelf previewController:blockController updateAttachment:attachment data:data];
876+
});
877+
}];
878+
[task resume];
899879
return attachment;
900880
} else {
901881
return self.cachedPreviewItems[index];

Classes/BITFeedbackManager.m

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -979,29 +979,18 @@ - (void)sendNetworkRequestWithHTTPMethod:(NSString *)httpMethod withMessage:(BIT
979979
[request setHTTPBody:postBody];
980980
}
981981
__weak typeof(self) weakSelf = self;
982-
if ([BITHockeyHelper isURLSessionSupported]) {
983-
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
984-
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
982+
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
983+
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
985984

986-
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
987-
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
988-
typeof(self) strongSelf = weakSelf;
985+
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
986+
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
987+
typeof(self) strongSelf = weakSelf;
989988

990-
[session finishTasksAndInvalidate];
989+
[session finishTasksAndInvalidate];
991990

992-
[strongSelf handleFeedbackMessageResponse:response data:data error:error completion:completionHandler];
993-
}];
994-
[task resume];
995-
996-
} else {
997-
#pragma clang diagnostic push
998-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
999-
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *responseData, NSError *error) {
1000-
#pragma clang diagnostic pop
1001-
typeof(self) strongSelf = weakSelf;
1002-
[strongSelf handleFeedbackMessageResponse:response data:responseData error:error completion:completionHandler];
1003-
}];
1004-
}
991+
[strongSelf handleFeedbackMessageResponse:response data:data error:error completion:completionHandler];
992+
}];
993+
[task resume];
1005994

1006995
}
1007996

0 commit comments

Comments
 (0)