From 422235caec540eb0d417b30bd8e1de5939b2b419 Mon Sep 17 00:00:00 2001 From: Andreas Linde Date: Tue, 23 Jun 2015 10:59:22 +0200 Subject: [PATCH] Fix iOS 7.1 unit test and make upload more robust --- Classes/BITCrashManager.m | 34 +++++++++++-------- Support/HockeySDKTests/BITCrashManagerTests.m | 8 +++++ 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Classes/BITCrashManager.m b/Classes/BITCrashManager.m index 22df28e397..95b71ec19b 100644 --- a/Classes/BITCrashManager.m +++ b/Classes/BITCrashManager.m @@ -1590,6 +1590,8 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf * @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; + id nsurlsessionClass = NSClassFromString(@"NSURLSessionUploadTask"); if (nsurlsessionClass && !bit_isRunningInAppExtension()) { NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; @@ -1598,20 +1600,24 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf NSURLRequest *request = [self requestWithBoundary:kBITHockeyAppClientBoundary]; NSData *data = [self postBodyWithXML:xml attachment:attachment boundary:kBITHockeyAppClientBoundary]; - __weak typeof (self) weakSelf = self; - NSURLSessionUploadTask *uploadTask = [session uploadTaskWithRequest:request - fromData:data - completionHandler:^(NSData *responseData, NSURLResponse *response, NSError *error) { - typeof (self) strongSelf = weakSelf; - - NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*) response; - NSInteger statusCode = [httpResponse statusCode]; - [strongSelf processUploadResultWithFilename:filename responseData:responseData statusCode:statusCode error:error]; - }]; - - // 5 - [uploadTask resume]; - } else { + 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; + + 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]; diff --git a/Support/HockeySDKTests/BITCrashManagerTests.m b/Support/HockeySDKTests/BITCrashManagerTests.m index 2171c803fd..aeda451b2b 100644 --- a/Support/HockeySDKTests/BITCrashManagerTests.m +++ b/Support/HockeySDKTests/BITCrashManagerTests.m @@ -22,6 +22,8 @@ #import "BITHockeyBaseManagerPrivate.h" #import "BITTestHelper.h" +#import "BITHockeyAppClient.h" + #define kBITCrashMetaAttachment @"BITCrashMetaAttachment" @@ -32,6 +34,7 @@ @implementation BITCrashManagerTests { BITCrashManager *_sut; + BITHockeyAppClient *_hockeyAppClient; BOOL _startManagerInitialized; } @@ -40,6 +43,11 @@ _startManagerInitialized = NO; _sut = [[BITCrashManager alloc] initWithAppIdentifier:nil isAppStoreEnvironment:NO]; + + _hockeyAppClient = [[BITHockeyAppClient alloc] initWithBaseURL:[NSURL URLWithString: BITHOCKEYSDK_URL]]; + _hockeyAppClient.baseURL = [NSURL URLWithString:BITHOCKEYSDK_URL]; + + [_sut setHockeyAppClient:_hockeyAppClient]; } - (void)tearDown {