NSURLConnection removed

This commit is contained in:
Murat Baysangurov
2017-07-27 11:08:40 +03:00
parent d2a014bc66
commit f265ebb069
19 changed files with 119 additions and 813 deletions

View File

@@ -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"
@@ -322,29 +321,20 @@ static unsigned char kBITPNGEndChunk[4] = {0x49, 0x45, 0x4e, 0x44};
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 {
@@ -481,32 +471,19 @@ static unsigned char kBITPNGEndChunk[4] = {0x49, 0x45, 0x4e, 0x44};
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 {

View File

@@ -1701,51 +1701,27 @@ __attribute__((noreturn)) static void uncaught_cxx_exception_handler(const BITCr
* @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];
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
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];
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:)]) {

View File

@@ -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;

View File

@@ -605,31 +605,21 @@
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;
@@ -869,30 +859,20 @@
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];

View File

@@ -979,29 +979,18 @@ typedef void (^BITLatestImageFetchCompletionBlock)(UIImage *_Nonnull latestImage
[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];
}

View File

@@ -1,47 +0,0 @@
/*
* Author: Stephan Diederich
*
* Copyright (c) 2013-2014 HockeyApp, Bit Stadium GmbH.
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#import <Foundation/Foundation.h>
@class BITHTTPOperation;
typedef void (^BITNetworkCompletionBlock)(BITHTTPOperation* operation, NSData* data, NSError* error);
@interface BITHTTPOperation : NSOperation
+ (instancetype) operationWithRequest:(NSURLRequest *) urlRequest;
@property (nonatomic, readonly) NSURLRequest *URLRequest;
//the completion is only called if the operation wasn't cancelled
- (void) setCompletion:(BITNetworkCompletionBlock) completionBlock;
@property (nonatomic, readonly) NSHTTPURLResponse *response;
@property (nonatomic, readonly) NSData *data;
@property (nonatomic, readonly) NSError *error;
@end

View File

@@ -1,154 +0,0 @@
/*
* Author: Stephan Diederich
*
* Copyright (c) 2013-2014 HockeyApp, Bit Stadium GmbH.
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#import "BITHTTPOperation.h"
@interface BITHTTPOperation() <NSURLConnectionDelegate>
@property (nonatomic, strong) NSURLRequest *URLRequest;
@property (nonatomic, strong) NSURLConnection *connection;
@property (nonatomic, strong) NSMutableData *mutableData;
@property (nonatomic) BOOL isExecuting;
@property (nonatomic) BOOL isFinished;
// Redeclare BITHTTPOperation properties with readwrite attribute.
@property (nonatomic, readwrite) NSHTTPURLResponse *response;
@property (nonatomic, readwrite) NSError *error;
@end
@implementation BITHTTPOperation
+ (instancetype)operationWithRequest:(NSURLRequest *)urlRequest {
BITHTTPOperation *op = [[self class] new];
op.URLRequest = urlRequest;
return op;
}
#pragma mark - NSOperation overrides
- (BOOL)isConcurrent {
return YES;
}
- (void)cancel {
[self.connection cancel];
[super cancel];
}
- (void) start {
if(self.isCancelled) {
[self finish];
return;
}
if (![[NSThread currentThread] isMainThread]) {
[self performSelector:@selector(start) onThread:NSThread.mainThread withObject:nil waitUntilDone:NO];
return;
}
if(self.isCancelled) {
[self finish];
return;
}
[self willChangeValueForKey:@"isExecuting"];
self.isExecuting = YES;
[self didChangeValueForKey:@"isExecuting"];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
self.connection = [[NSURLConnection alloc] initWithRequest:self.URLRequest
delegate:self
startImmediately:YES];
#pragma clang diagnostic pop
}
- (void) finish {
[self willChangeValueForKey:@"isExecuting"];
[self willChangeValueForKey:@"isFinished"];
self.isExecuting = NO;
self.isFinished = YES;
[self didChangeValueForKey:@"isExecuting"];
[self didChangeValueForKey:@"isFinished"];
}
#pragma mark - NSURLConnectionDelegate
-(void)connection:(NSURLConnection*) __unused connection didReceiveResponse:(NSURLResponse*)response {
self.mutableData = [[NSMutableData alloc] init];
self.response = (id)response;
}
-(void)connection:(NSURLConnection*) __unused connection didReceiveData:(NSData*)data {
[self.mutableData appendData:data];
}
-(void)connection:(NSURLConnection*) __unused connection didFailWithError:(NSError*)error {
//FINISHED and failed
self.error = error;
self.mutableData = nil;
[self finish];
}
-(void)connectionDidFinishLoading:(NSURLConnection*) __unused connection {
[self finish];
}
#pragma mark - Public interface
- (NSData *)data {
return self.mutableData;
}
- (void)setCompletion:(BITNetworkCompletionBlock)completion {
if(!completion) {
[super setCompletionBlock:nil];
} else {
__weak typeof(self) weakSelf = self;
[super setCompletionBlock:^{
typeof(self) strongSelf = weakSelf;
if(strongSelf) {
dispatch_async(dispatch_get_main_queue(), ^{
if(!strongSelf.isCancelled) {
completion(strongSelf, strongSelf.data, strongSelf.error);
}
[strongSelf setCompletionBlock:nil];
});
}
}];
}
}
- (BOOL)isFinished {
return _isFinished;
}
- (BOOL)isExecuting {
return _isExecuting;
}
@end

View File

@@ -28,8 +28,6 @@
#import <Foundation/Foundation.h>
#import "BITHTTPOperation.h" //needed for typedef
extern NSString * const kBITHockeyAppClientBoundary;
/**
@@ -62,56 +60,6 @@ extern NSString * const kBITHockeyAppClientBoundary;
- (NSMutableURLRequest *) requestWithMethod:(NSString*) method
path:(NSString *) path
parameters:(NSDictionary *) params;
/**
* Creates an operation for the given NSURLRequest
*
* @param request the request that should be handled
* @param completion completionBlock that is called once the operation finished
*
* @return operation, which can be queued via enqueueHTTPOperation:
*/
- (BITHTTPOperation*) operationWithURLRequest:(NSURLRequest*) request
completion:(BITNetworkCompletionBlock) completion;
/**
* Creates an operation for the given path, and enqueues it
*
* @param path the request path to check
* @param params parameters for the request
* @param completion completionBlock that is called once the operation finished
*
*/
- (void) getPath:(NSString*) path
parameters:(NSDictionary *) params
completion:(BITNetworkCompletionBlock) completion;
/**
* Creates an operation for the given path, and enqueues it
*
* @param path the request path to check
* @param params parameters for the request
* @param completion completionBlock that is called once the operation finished
*
*/
- (void) postPath:(NSString*) path
parameters:(NSDictionary *) params
completion:(BITNetworkCompletionBlock) completion;
/**
* adds the given operation to the internal queue
*
* @param operation operation to add
*/
- (void) enqeueHTTPOperation:(BITHTTPOperation *) operation;
/**
* cancels the specified operations
*
* @param path the path which operation should be cancelled. Can be nil to match all
* @param method the method which operations to cancel. Can be nil to match all
* @return number of operations cancelled
*/
- (NSUInteger) cancelOperationsWithPath:(NSString*) path
method:(NSString*) method;
/**
* Access to the internal operation queue

View File

@@ -30,9 +30,6 @@
NSString * const kBITHockeyAppClientBoundary = @"----FOO";
@implementation BITHockeyAppClient
- (void)dealloc {
[self cancelOperationsWithPath:nil method:nil];
}
- (instancetype)initWithBaseURL:(NSURL *)baseURL {
self = [super init];
@@ -122,59 +119,6 @@ NSString * const kBITHockeyAppClientBoundary = @"----FOO";
return queryString;
}
- (BITHTTPOperation*) operationWithURLRequest:(NSURLRequest*) request
completion:(BITNetworkCompletionBlock) completion {
BITHTTPOperation *operation = [BITHTTPOperation operationWithRequest:request
];
[operation setCompletion:completion];
return operation;
}
- (void)getPath:(NSString *)path parameters:(NSDictionary *)params completion:(BITNetworkCompletionBlock)completion {
NSURLRequest *request = [self requestWithMethod:@"GET" path:path parameters:params];
BITHTTPOperation *op = [self operationWithURLRequest:request
completion:completion];
[self enqeueHTTPOperation:op];
}
- (void)postPath:(NSString *)path parameters:(NSDictionary *)params completion:(BITNetworkCompletionBlock)completion {
NSURLRequest *request = [self requestWithMethod:@"POST" path:path parameters:params];
BITHTTPOperation *op = [self operationWithURLRequest:request
completion:completion];
[self enqeueHTTPOperation:op];
}
- (void) enqeueHTTPOperation:(BITHTTPOperation *) operation {
[self.operationQueue addOperation:operation];
}
- (NSUInteger) cancelOperationsWithPath:(NSString*) path
method:(NSString*) method {
NSUInteger cancelledOperations = 0;
for(BITHTTPOperation *operation in self.operationQueue.operations) {
NSURLRequest *request = operation.URLRequest;
BOOL matchedMethod = YES;
if(method && ![request.HTTPMethod isEqualToString:method]) {
matchedMethod = NO;
}
BOOL matchedPath = YES;
if(path) {
//method is not interesting here, we' just creating it to get the URL
NSURL *url = [self requestWithMethod:@"GET" path:path parameters:nil].URL;
matchedPath = [request.URL isEqual:url];
}
if(matchedPath && matchedMethod) {
++cancelledOperations;
[operation cancel];
}
}
return cancelledOperations;
}
- (NSOperationQueue *)operationQueue {
if(nil == _operationQueue) {
_operationQueue = [[NSOperationQueue alloc] init];

View File

@@ -602,26 +602,18 @@ static bitstadium_info_t bitstadium_library_info __attribute__((section("__TEXT,
@"bundle_version": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]
};
if ([BITHockeyHelper isURLSessionSupported]) {
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
NSURLRequest *request = [[self hockeyAppClient] requestWithMethod:@"POST" path:integrationPath parameters:params];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler: ^(NSData * __unused data, NSURLResponse *response, NSError * __unused error) {
[session finishTasksAndInvalidate];
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*) response;
[self logPingMessageForStatusCode:httpResponse.statusCode];
}];
[task resume];
}else{
[[self hockeyAppClient] postPath:integrationPath
parameters:params
completion:^(BITHTTPOperation *operation, NSData * __unused responseData, NSError * __unused error) {
[self logPingMessageForStatusCode:operation.response.statusCode];
}];
}
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
__block NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
NSURLRequest *request = [[self hockeyAppClient] requestWithMethod:@"POST" path:integrationPath parameters:params];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler: ^(NSData * __unused data, NSURLResponse *response, NSError * __unused error) {
[session finishTasksAndInvalidate];
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*) response;
[self logPingMessageForStatusCode:httpResponse.statusCode];
}];
[task resume];
}
- (void)logPingMessageForStatusCode:(NSInteger)statusCode {

View File

@@ -32,7 +32,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong) dispatch_queue_t requestsCountQueue;
/**
* A queue which is used to handle BITHTTPOperation completion blocks.
* A queue which is used to handle completion blocks.
*/
@property (nonatomic, strong) dispatch_queue_t senderTasksQueue;
@@ -105,8 +105,6 @@ NS_ASSUME_NONNULL_BEGIN
- (void)sendUsingURLSessionWithRequest:(NSURLRequest *)request filePath:(NSString *)filePath;
- (void)sendUsingURLConnectionWithRequest:(NSURLRequest *)request filePath:(NSString *)filePath;
/**
* Resumes the given NSURLSessionDataTask instance.
*

View File

@@ -6,7 +6,6 @@
#import "BITChannelPrivate.h"
#import "BITGZIP.h"
#import "HockeySDKPrivate.h"
#import "BITHTTPOperation.h"
#import "BITHockeyHelper.h"
static char const *kBITSenderTasksQueueString = "net.hockeyapp.sender.tasksQueue";
@@ -100,12 +99,7 @@ static NSUInteger const BITDefaultRequestLimit = 10;
- (void)sendRequest:(nonnull NSURLRequest *) request filePath:(nonnull NSString *) path {
if (!path || !request) {return;}
if ([self isURLSessionSupported]) {
[self sendUsingURLSessionWithRequest:request filePath:path];
} else {
[self sendUsingURLConnectionWithRequest:request filePath:path];
}
[self sendUsingURLSessionWithRequest:request filePath:path];
}
- (BOOL)isURLSessionSupported {
@@ -114,16 +108,6 @@ static NSUInteger const BITDefaultRequestLimit = 10;
return isUrlSessionSupported;
}
- (void)sendUsingURLConnectionWithRequest:(nonnull NSURLRequest *)request filePath:(nonnull NSString *)filePath {
BITHTTPOperation *operation = [BITHTTPOperation operationWithRequest:request];
[operation setCompletion:^(BITHTTPOperation *innerOperation, NSData *responseData, NSError *error) {
NSInteger statusCode = [innerOperation.response statusCode];
[self handleResponseWithStatusCode:statusCode responseData:responseData filePath:filePath error:error];
}];
[self.operationQueue addOperation:operation];
}
- (void)sendUsingURLSessionWithRequest:(nonnull NSURLRequest *)request filePath:(nonnull NSString *)filePath {
NSURLSession *session = self.session;
NSURLSessionDataTask *task = [session dataTaskWithRequest:request

View File

@@ -364,28 +364,18 @@
[request setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
__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 handleResponeWithData:data error:error];
}];
[task resume];
}else{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse __unused *response, NSData *responseData, NSError *error){
#pragma clang diagnostic pop
typeof (self) strongSelf = weakSelf;
[strongSelf handleResponeWithData:responseData error:error];
}];
}
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 handleResponeWithData:data error:error];
}];
[task resume];
}
- (void)handleResponeWithData:(NSData *)responseData error:(NSError *)error{

View File

@@ -506,8 +506,6 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
[self unregisterObservers];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillTerminateNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillResignActiveNotification object:nil];
[_urlConnection cancel];
}
@@ -850,31 +848,17 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
}
NSURLRequest *request = [self requestForUpdateCheck];
if ([BITHockeyHelper isURLSessionSupported]) {
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration delegate:(id<NSURLSessionDelegate>)self delegateQueue:nil];
NSURLSessionDataTask *sessionTask = [session dataTaskWithRequest:request];
if (!sessionTask) {
self.checkInProgress = NO;
[self reportError:[NSError errorWithDomain:kBITUpdateErrorDomain
code:BITUpdateAPIClientCannotCreateConnection
userInfo:@{NSLocalizedDescriptionKey : @"Url Connection could not be created."}]];
} else {
[sessionTask resume];
}
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration delegate:(id<NSURLSessionDelegate>)self delegateQueue:nil];
NSURLSessionDataTask *sessionTask = [session dataTaskWithRequest:request];
if (!sessionTask) {
self.checkInProgress = NO;
[self reportError:[NSError errorWithDomain:kBITUpdateErrorDomain
code:BITUpdateAPIClientCannotCreateConnection
userInfo:@{NSLocalizedDescriptionKey : @"Url Connection could not be created."}]];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
self.urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
#pragma clang diagnostic pop
if (!self.urlConnection) {
self.checkInProgress = NO;
[self reportError:[NSError errorWithDomain:kBITUpdateErrorDomain
code:BITUpdateAPIClientCannotCreateConnection
userInfo:@{NSLocalizedDescriptionKey : @"Url Connection could not be created."}]];
}
[sessionTask resume];
}
}
@@ -1017,7 +1001,6 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
- (void)handleError:(NSError *)error {
self.receivedData = nil;
self.urlConnection = nil;
self.checkInProgress = NO;
if ([self expiryDateReached]) {
if (!self.blockingView) {
@@ -1038,7 +1021,6 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
if (!responseString || ![responseString dataUsingEncoding:NSUTF8StringEncoding]) {
self.receivedData = nil;
self.urlConnection = nil;
return;
}
@@ -1057,7 +1039,6 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
if (![feedArray count]) {
BITHockeyLogDebug(@"WARNING: No versions available for download on HockeyApp.");
self.receivedData = nil;
self.urlConnection = nil;
return;
} else {
self.lastCheckFailed = NO;
@@ -1161,51 +1142,9 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
}
self.receivedData = nil;
self.urlConnection = nil;
}
}
#pragma mark - NSURLRequest
- (NSURLRequest *)connection:(NSURLConnection *) __unused connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse {
NSURLRequest *newRequest = request;
if (redirectResponse) {
newRequest = nil;
}
return newRequest;
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
if ([response respondsToSelector:@selector(statusCode)]) {
NSInteger statusCode = [((NSHTTPURLResponse *)response) statusCode];
if (statusCode == 404) {
[connection cancel]; // stop connecting; no more delegate messages
NSString *errorStr = [NSString stringWithFormat:@"Hockey API received HTTP Status Code %ld", (long)statusCode];
[self reportError:[NSError errorWithDomain:kBITUpdateErrorDomain
code:BITUpdateAPIServerReturnedInvalidStatus
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:errorStr, NSLocalizedDescriptionKey, nil]]];
return;
}
}
self.receivedData = [NSMutableData data];
[self.receivedData setLength:0];
}
- (void)connection:(NSURLConnection *) __unused connection didReceiveData:(NSData *)data {
[self.receivedData appendData:data];
}
- (void)connection:(NSURLConnection *) __unused connection didFailWithError:(NSError *)error {
[self handleError:error];
}
// api call returned, parsing
- (void)connectionDidFinishLoading:(NSURLConnection *) __unused connection {
[self finishLoading];
}
#pragma mark - NSURLSession
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *) __unused task didCompleteWithError:(NSError *)error {

View File

@@ -68,8 +68,6 @@
@property (nonatomic, strong) NSNumber *currentAppVersionUsageTime;
@property (nonatomic, strong) NSURLConnection *urlConnection;
@property (nonatomic, copy) NSDate *usageStartTimestamp;
@property (nonatomic, strong) UIView *blockingView;

View File

@@ -238,8 +238,6 @@
1EB617B81B0A31DB0035A986 /* BITTestHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 1EA1170616F53B91001C015C /* BITTestHelper.m */; };
1EB617B91B0A32780035A986 /* HockeySDKResources.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 1E59550A15B6F45800A03429 /* HockeySDKResources.bundle */; };
1EB617CB1B0A34040035A986 /* CrashReporter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E41EB48B148D7C4E0015DEDC /* CrashReporter.framework */; };
1EB617CD1B0A34440035A986 /* BITHTTPOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = E4933E7E17B66CDA00B11ACC /* BITHTTPOperation.h */; };
1EB617CE1B0A34470035A986 /* BITHTTPOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = E4933E7F17B66CDA00B11ACC /* BITHTTPOperation.m */; };
1EB617CF1B0A344A0035A986 /* BITHockeyAppClient.h in Headers */ = {isa = PBXBuildFile; fileRef = E40E0B0A17DA1AFF005E38C1 /* BITHockeyAppClient.h */; };
1EB617D01B0A344D0035A986 /* BITHockeyAppClient.m in Sources */ = {isa = PBXBuildFile; fileRef = E40E0B0B17DA1AFF005E38C1 /* BITHockeyAppClient.m */; };
1EB6181E1B0A5FA50035A986 /* BITAuthenticator_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = E48A3DF117B408F400924C3D /* BITAuthenticator_Private.h */; };
@@ -438,8 +436,6 @@
E48A3DEC17B3ED1C00924C3D /* BITAuthenticator.h in Headers */ = {isa = PBXBuildFile; fileRef = E48A3DEA17B3ED1C00924C3D /* BITAuthenticator.h */; settings = {ATTRIBUTES = (Public, ); }; };
E48A3DED17B3ED1C00924C3D /* BITAuthenticator.m in Sources */ = {isa = PBXBuildFile; fileRef = E48A3DEB17B3ED1C00924C3D /* BITAuthenticator.m */; };
E48A3DEF17B3EFF100924C3D /* BITAuthenticatorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E48A3DEE17B3EFF100924C3D /* BITAuthenticatorTests.m */; };
E4933E8017B66CDA00B11ACC /* BITHTTPOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = E4933E7E17B66CDA00B11ACC /* BITHTTPOperation.h */; };
E4933E8117B66CDA00B11ACC /* BITHTTPOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = E4933E7F17B66CDA00B11ACC /* BITHTTPOperation.m */; };
E4B4DB7D17B435550099C67F /* BITAuthenticationViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = E4B4DB7B17B435550099C67F /* BITAuthenticationViewController.h */; };
E4B4DB7E17B435550099C67F /* BITAuthenticationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E4B4DB7C17B435550099C67F /* BITAuthenticationViewController.m */; };
/* End PBXBuildFile section */
@@ -777,8 +773,6 @@
E48A3DEB17B3ED1C00924C3D /* BITAuthenticator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BITAuthenticator.m; sourceTree = "<group>"; };
E48A3DEE17B3EFF100924C3D /* BITAuthenticatorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BITAuthenticatorTests.m; sourceTree = "<group>"; };
E48A3DF117B408F400924C3D /* BITAuthenticator_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BITAuthenticator_Private.h; sourceTree = "<group>"; };
E4933E7E17B66CDA00B11ACC /* BITHTTPOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BITHTTPOperation.h; sourceTree = "<group>"; };
E4933E7F17B66CDA00B11ACC /* BITHTTPOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BITHTTPOperation.m; sourceTree = "<group>"; };
E4B4DB7B17B435550099C67F /* BITAuthenticationViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BITAuthenticationViewController.h; sourceTree = "<group>"; };
E4B4DB7C17B435550099C67F /* BITAuthenticationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BITAuthenticationViewController.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -1329,22 +1323,12 @@
E48A3DE917B3ECF900924C3D /* Network */ = {
isa = PBXGroup;
children = (
E48A3DF017B408D800924C3D /* private */,
E40E0B0A17DA1AFF005E38C1 /* BITHockeyAppClient.h */,
E40E0B0B17DA1AFF005E38C1 /* BITHockeyAppClient.m */,
);
name = Network;
sourceTree = "<group>";
};
E48A3DF017B408D800924C3D /* private */ = {
isa = PBXGroup;
children = (
E4933E7E17B66CDA00B11ACC /* BITHTTPOperation.h */,
E4933E7F17B66CDA00B11ACC /* BITHTTPOperation.m */,
);
name = private;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
@@ -1406,7 +1390,6 @@
1E49A4B5161222B900463151 /* BITHockeyBaseManagerPrivate.h in Headers */,
9774BCFF192CB20A00085EB5 /* BITActivityIndicatorButton.h in Headers */,
8034E6961BA3214300D83A30 /* BITCategoryContainer.h in Headers */,
E4933E8017B66CDA00B11ACC /* BITHTTPOperation.h in Headers */,
1E49A4BE161222B900463151 /* BITHockeyHelper.h in Headers */,
973EC8BB18BDE29800DBFFBB /* BITArrowImageAnnotation.h in Headers */,
1E49A4C4161222B900463151 /* BITAppStoreHeader.h in Headers */,
@@ -1474,7 +1457,6 @@
1EB6177D1B0A311A0035A986 /* BITCrashAttachment.h in Headers */,
1EB617AA1B0A31B10035A986 /* BITStoreUpdateManagerPrivate.h in Headers */,
8034E6A61BA3217400D83A30 /* BITSessionStateData.h in Headers */,
1EB617CD1B0A34440035A986 /* BITHTTPOperation.h in Headers */,
8034E66E1BA31D7C00D83A30 /* BITBase.h in Headers */,
1EB617A11B0A318B0035A986 /* BITFeedbackManagerPrivate.h in Headers */,
1EB6177B1B0A31120035A986 /* BITCrashMetaData.h in Headers */,
@@ -1824,7 +1806,6 @@
8034E69C1BA3216000D83A30 /* BITInternal.m in Sources */,
8034E67F1BA31D7C00D83A30 /* BITEnvelope.m in Sources */,
1ECA8F52192B6954006B9416 /* BITCrashMetaData.m in Sources */,
E4933E8117B66CDA00B11ACC /* BITHTTPOperation.m in Sources */,
1E49A45A1612223B00463151 /* BITFeedbackMessage.m in Sources */,
1ED570C818BF878C00AB3350 /* BITCrashAttachment.m in Sources */,
1E49A4601612223B00463151 /* BITFeedbackUserDataViewController.m in Sources */,
@@ -1956,7 +1937,6 @@
1EB617901B0A31510035A986 /* BITActivityIndicatorButton.m in Sources */,
1EB6178E1B0A31510035A986 /* BITFeedbackActivity.m in Sources */,
1EB617661B0A30B60035A986 /* BITKeychainUtils.m in Sources */,
1EB617CE1B0A34470035A986 /* BITHTTPOperation.m in Sources */,
1EB617741B0A30EE0035A986 /* BITAuthenticator.m in Sources */,
1EB6176A1B0A30C30035A986 /* BITAppStoreHeader.m in Sources */,
1EB617831B0A31350035A986 /* BITImageAnnotation.m in Sources */,

View File

@@ -17,7 +17,6 @@
#import "BITHockeyHelper.h"
#import "BITAuthenticator_Private.h"
#import "BITHockeyBaseManagerPrivate.h"
#import "BITHTTPOperation.h"
#import "BITTestHelper.h"
#import "BITHockeyAppClient.h"
@@ -222,21 +221,6 @@ static void *kInstallationIdentification = &kInstallationIdentification;
}];
}
- (void) testThatEmailIdentificationQueuesAnOperation {
id helperMock = OCMClassMock([BITHockeyHelper class]);
OCMStub([helperMock isURLSessionSupported]).andReturn(NO);
id httpClientMock = mock(BITHockeyAppClient.class);
_sut.hockeyAppClient = httpClientMock;
_sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppEmail;
[_sut storeInstallationIdentifier:@"meh" withType:BITAuthenticatorIdentificationTypeHockeyAppEmail];
_sut.authenticationSecret = @"double";
[_sut authenticationViewController:nil handleAuthenticationWithEmail:@"stephan@dd.de" request:[NSURLRequest new] completion:nil];
[verify(httpClientMock) enqeueHTTPOperation:anything()];
}
#pragma mark - User identification type
- (void) testUserIdentificationShowsViewController {
_sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppUser;
@@ -259,20 +243,6 @@ static void *kInstallationIdentification = &kInstallationIdentification;
}];
}
- (void) testThatValidationCreatesAGETRequest {
id helperMock = OCMClassMock([BITHockeyHelper class]);
OCMStub([helperMock isURLSessionSupported]).andReturn(NO);
id httpClientMock = mock(BITHockeyAppClient.class);
_sut.hockeyAppClient = httpClientMock;
_sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppEmail;
[_sut storeInstallationIdentifier:@"meh" withType:BITAuthenticatorIdentificationTypeHockeyAppEmail];
_sut.authenticationSecret = @"double";
[_sut validateWithCompletion:nil];
[verify(httpClientMock) getPath:(id)anything()
parameters:(id)anything()
completion:(id)anything()];
}
#pragma mark - Authentication
- (void) testThatEnabledRestrictionTriggersValidation {
id mockAuthenticator = OCMPartialMock(_sut);
@@ -287,18 +257,6 @@ static void *kInstallationIdentification = &kInstallationIdentification;
OCMVerifyAll(mockAuthenticator);
}
- (void) testThatDisabledRestrictionDoesntTriggerValidation {
id clientMock = mock(BITHockeyAppClient.class);
_sut.hockeyAppClient = clientMock;
_sut.authenticationSecret = @"sekret";
_sut.restrictApplicationUsage = NO;
_sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppEmail;
[_sut storeInstallationIdentifier:@"asd" withType:BITAuthenticatorIdentificationTypeHockeyAppEmail];
[_sut authenticate];
[verifyCount(clientMock, never()) getPath:(id)anything() parameters:(id)anything() completion:(id)anything()];
}
#pragma mark - Lifetime checks
- (void) testThatValidationTriggersOnDidBecomeActive {
id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate));

View File

@@ -13,7 +13,6 @@
#import "HockeySDK.h"
#import "BITHockeyAppClient.h"
#import "BITHTTPOperation.h"
#import "BITTestHelper.h"
@interface BITHockeyAppClientTests : XCTestCase
@@ -30,7 +29,6 @@
}
- (void)tearDown {
[_sut cancelOperationsWithPath:nil method:nil];
_sut = nil;
[super tearDown];
@@ -71,14 +69,6 @@
assertThat(request.HTTPMethod, equalTo(@"POST"));
}
- (void) testThatOperationHasURLRequestSet {
_sut.baseURL = [NSURL URLWithString:@"http://myserver.com"];
NSURLRequest *r = [_sut requestWithMethod:@"PUT" path:@"x" parameters:nil];
BITHTTPOperation *op = [_sut operationWithURLRequest:r
completion:nil];
assertThat(op.URLRequest, equalTo(r));
}
- (void) testThatURLRequestHasParametersInGetAppended {
NSDictionary *parameters = @{
@"email" : @"peter@pan.de",
@@ -105,124 +95,9 @@
//pending
}
#pragma mark - Convenience methods
- (void) testThatGetPathCreatesAndEnquesAnOperation {
assertThatUnsignedLong(_sut.operationQueue.operationCount, equalToUnsignedLong(0));
[given([_sut operationWithURLRequest:(id)anything()
completion:nil]) willReturn:[NSOperation new]];
[_sut getPath:@"endpoint"
parameters:nil
completion:nil];
assertThatUnsignedLong(_sut.operationQueue.operationCount, equalToUnsignedLong(1));
}
- (void) testThatPostPathCreatesAndEnquesAnOperation {
assertThatUnsignedLong(_sut.operationQueue.operationCount, equalToUnsignedLong(0));
[given([_sut operationWithURLRequest:nil
completion:nil]) willReturn:[NSOperation new]];
[_sut postPath:@"endpoint"
parameters:nil
completion:nil];
assertThatUnsignedLong(_sut.operationQueue.operationCount, equalToUnsignedLong(1));
}
#pragma mark - Completion Tests
- (void) testThatCompletionIsCalled {
//TODO
}
#pragma mark - HTTPOperation enqueuing / cancellation
- (void) testThatOperationIsQueued {
assertThatUnsignedLong(_sut.operationQueue.operationCount, equalToUnsignedLong(0));
[_sut.operationQueue setSuspended:YES];
BITHTTPOperation *op = [BITHTTPOperation new];
[_sut enqeueHTTPOperation:op];
assertThatUnsignedLong(_sut.operationQueue.operationCount, equalToUnsignedLong(1));
}
- (void) testThatOperationCancellingMatchesAllOperationsWithNilMethod {
[_sut.operationQueue setSuspended:YES];
NSURLRequest *requestGet = [_sut requestWithMethod:@"GET" path:nil parameters:nil];
NSURLRequest *requestPut = [_sut requestWithMethod:@"PUT" path:nil parameters:nil];
NSURLRequest *requestPost = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestGet
completion:nil]];
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPut
completion:nil]];
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPost
completion:nil]];
assertThatUnsignedLong(_sut.operationQueue.operationCount, equalToUnsignedLong(3));
NSUInteger numCancelled = [_sut cancelOperationsWithPath:nil method:nil];
assertThatUnsignedLong(numCancelled, equalToUnsignedLong(3));
}
- (void) testThatOperationCancellingMatchesAllOperationsWithNilPath {
[_sut.operationQueue setSuspended:YES];
NSURLRequest *requestGet = [_sut requestWithMethod:@"GET" path:@"test" parameters:nil];
NSURLRequest *requestPut = [_sut requestWithMethod:@"PUT" path:@"Another/acas" parameters:nil];
NSURLRequest *requestPost = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestGet
completion:nil]];
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPut
completion:nil]];
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPost
completion:nil]];
assertThatUnsignedLong(_sut.operationQueue.operationCount, equalToUnsignedLong(3));
NSUInteger numCancelled = [_sut cancelOperationsWithPath:nil method:nil];
assertThatUnsignedLong(numCancelled, equalToUnsignedLong(3));
}
- (void) testThatOperationCancellingMatchesAllOperationsWithSetPath {
NSURLRequest *requestGet = [_sut requestWithMethod:@"GET" path:@"test" parameters:nil];
NSURLRequest *requestPut = [_sut requestWithMethod:@"PUT" path:@"Another/acas" parameters:nil];
NSURLRequest *requestPost = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
[_sut.operationQueue setSuspended:YES];
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestGet
completion:nil]];
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPut
completion:nil]];
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPost
completion:nil]];
assertThatUnsignedLong(_sut.operationQueue.operationCount, equalToUnsignedLong(3));
NSUInteger numCancelled = [_sut cancelOperationsWithPath:@"Another/acas" method:nil];
assertThatUnsignedLong(numCancelled, equalToUnsignedLong(1));
}
- (void) testThatOperationCancellingMatchesAllOperationsWithSetMethod {
NSURLRequest *requestGet = [_sut requestWithMethod:@"GET" path:@"test" parameters:nil];
NSURLRequest *requestPut = [_sut requestWithMethod:@"PUT" path:@"Another/acas" parameters:nil];
NSURLRequest *requestPost = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestGet
completion:nil]];
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPut
completion:nil]];
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPost
completion:nil]];
assertThatUnsignedLong(_sut.operationQueue.operationCount, equalToUnsignedLong(3));
NSUInteger numCancelled = [_sut cancelOperationsWithPath:nil method:@"POST"];
assertThatUnsignedLong(numCancelled, equalToUnsignedLong(1));
}
- (void) testThatOperationCancellingMatchesAllOperationsWithSetMethodAndPath {
NSURLRequest *requestGet = [_sut requestWithMethod:@"GET" path:@"test" parameters:nil];
NSURLRequest *requestPut = [_sut requestWithMethod:@"PUT" path:@"Another/acas" parameters:nil];
NSURLRequest *requestPost = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestGet
completion:nil]];
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPut
completion:nil]];
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPost
completion:nil]];
assertThatUnsignedLong(_sut.operationQueue.operationCount, equalToUnsignedLong(3));
NSUInteger numCancelled = [_sut cancelOperationsWithPath:@"Another/acas" method:@"PUT"];
assertThatUnsignedLong(numCancelled, equalToUnsignedLong(1));
}
#pragma mark - Operation Testing
@end

View File

@@ -64,13 +64,6 @@
[_sut sendRequest:testRequest filePath:testFilePath];
OCMVerify([_sut sendUsingURLSessionWithRequest:testRequest filePath:testFilePath]);
_sut = OCMPartialMock([self newSender]);
OCMStub([_sut isURLSessionSupported]).andReturn(NO);
[_sut sendRequest:testRequest filePath:testFilePath];
OCMVerify([_sut sendUsingURLConnectionWithRequest:testRequest filePath:testFilePath]);
}
- (void)testSendDataVerifyDataIsGzipped {
@@ -96,20 +89,6 @@
}] filePath:testFilePath]);
}
- (void)testSendUsingURLConnection {
// setup
_sut = OCMPartialMock(_sut);
NSString *testFilePath = @"path/to/file";
NSURLRequest *testRequest = [NSURLRequest new];
// test
[_sut sendUsingURLConnectionWithRequest:testRequest filePath:testFilePath];
//verify
OCMVerify([_sut.operationQueue addOperation:(id)anything()]);
}
- (void)testSendUsingURLSession {
// setup=