diff --git a/README.md b/README.md index 81a68a07..d154cc93 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,9 @@ Requires **iOS 5.0 or later**. ## Usage ### Import library + +Soon on Cocoapods. + 1. Drag and drop `TCBlobDownload.xcodeproj` from Finder to your opened project. 2. Open your Project's Target -> Build Phases -> **Target Dependencies** and add `TCBlobDownload`. Then, click **Link binary with libraries** and add `libTCBlobDownload.a` (no worries if it's red). 3. Go to **build settings**, switch "always search user paths" to `YES` and add `$(PROJECT_TEMP_DIR)/../UninstalledProducts/include` to "User Header Search Paths". diff --git a/TCBlobDownload/TCBlobDownload/TCBlobDownloadManager.m b/TCBlobDownload/TCBlobDownload/TCBlobDownloadManager.m index fde8c98f..c276a0b1 100644 --- a/TCBlobDownload/TCBlobDownload/TCBlobDownloadManager.m +++ b/TCBlobDownload/TCBlobDownload/TCBlobDownloadManager.m @@ -127,7 +127,6 @@ - (void)cancelAllDownloadsAndRemoveFiles:(BOOL)remove #pragma mark - Custom - + (BOOL)createPathFromPath:(NSString *)path { NSFileManager *fm = [NSFileManager defaultManager]; diff --git a/TCBlobDownload/TCBlobDownloadTests/TCBlobDownloadErrorTests.m b/TCBlobDownload/TCBlobDownloadTests/TCBlobDownloadErrorTests.m index 380e1e9d..f5356cfa 100644 --- a/TCBlobDownload/TCBlobDownloadTests/TCBlobDownloadErrorTests.m +++ b/TCBlobDownload/TCBlobDownloadTests/TCBlobDownloadErrorTests.m @@ -29,10 +29,8 @@ - (void)setUp withIntermediateDirectories:YES attributes:nil error:&error]; - if (error) { - XCTFail(@"Error while creating tests directory"); - NSLog(@"Error : %d - %@", error.code, error.localizedDescription); - } + + XCTAssertNil(error, @"Error while creating tests directory - %@", error); [self.manager setDefaultDownloadPath:[NSString pathWithComponents:@[NSTemporaryDirectory(), pathToDownloadTests]]]; } @@ -44,17 +42,15 @@ - (void)tearDown __autoreleasing NSError *error; [[NSFileManager defaultManager]removeItemAtPath:[NSString pathWithComponents:@[NSTemporaryDirectory(), pathToDownloadTests]] error:&error]; - if (error) { - XCTFail(@"Error while removing tests directory"); - NSLog(@"Error : %d - %@", error.code, error.localizedDescription); - } + + XCTAssertNil(error, @"Error while removing tests directory - %@", error); [super tearDown]; } - (void)testInvalidURL { - [self.manager startDownloadWithURL:[NSURL URLWithString:kInvalidURLToDownload] + /*[self.manager startDownloadWithURL:[NSURL URLWithString:kInvalidURLToDownload] customPath:nil firstResponse:NULL progress:NULL @@ -64,23 +60,12 @@ - (void)testInvalidURL } complete:NULL]; - [self waitForStatus:XCTAsyncTestCaseStatusSucceeded timeout:5]; + [self waitForStatus:XCTAsyncTestCaseStatusSucceeded timeout:5];*/ } -/*- (void)testHTTPErrorStatusCode +- (void)testHTTPErrorStatusCode { - [self.manager startDownloadWithURL:[NSURL URLWithString:k404URLToDownload] - customPath:nil - firstResponse:NULL - progress:NULL - error:^(NSError *error) { - XCTAssertNotNil(error, @"No error passed for 404 URL"); - XCTAssertEqual(error.userInfo[HTTPErrorCode], @(404), @"HTTP status code is not equal to 404"); - [self notify:XCTAsyncTestCaseStatusSucceeded]; - } - complete:NULL]; - - [self waitForStatus:XCTAsyncTestCaseStatusSucceeded timeout:5]; -}*/ + +} @end diff --git a/TCBlobDownload/TCBlobDownloadTests/TCBlobDownloadTests.m b/TCBlobDownload/TCBlobDownloadTests/TCBlobDownloadTests.m index 4af7f0d7..74383792 100644 --- a/TCBlobDownload/TCBlobDownloadTests/TCBlobDownloadTests.m +++ b/TCBlobDownload/TCBlobDownloadTests/TCBlobDownloadTests.m @@ -31,10 +31,8 @@ - (void)setUp withIntermediateDirectories:YES attributes:nil error:&error]; - if (error) { - XCTFail(@"Error while creating tests directory"); - NSLog(@"Error : %d - %@", error.code, error.localizedDescription); - } + + XCTAssertNil(error, @"Error while creating tests directory - %@", error); [self.manager setDefaultDownloadPath:[NSString pathWithComponents:@[NSTemporaryDirectory(), pathToDownloadTests]]]; } @@ -47,10 +45,8 @@ - (void)tearDown __autoreleasing NSError *error; [[NSFileManager defaultManager]removeItemAtPath:[NSString pathWithComponents:@[NSTemporaryDirectory(), pathToDownloadTests]] error:&error]; - if (error) { - XCTFail(@"Error while removing tests directory"); - NSLog(@"Error : %d - %@", error.code, error.localizedDescription); - } + + XCTAssertNil(error, @"Error while removing tests directory - %@", error); [super tearDown]; } @@ -137,21 +133,32 @@ - (void)testShouldHandleNilDownloadPath - (void)testCreateDownloadDirectory { - NSString *testDirectory = [NSString pathWithComponents:@[self.manager.defaultDownloadPath, @"createme"]]; + NSString *testDirectory = [NSString pathWithComponents:@[self.manager.defaultDownloadPath, @"create_me"]]; - [self.manager startDownloadWithURL:self.validURL + /*[self.manager startDownloadWithURL:self.validURL customPath:testDirectory firstResponse:^(NSURLResponse *response) { - BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:testDirectory]; - XCTAssert(exists, @"Custom download directory not created"); - [self notify:XCTAsyncTestCaseStatusSucceeded]; } - progress:NULL + progress:^(float receivedLength, float totalLength) { + BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:testDirectory]; + XCTAssert(exists, @"Custom download directory not created"); + + [self notify:XCTAsyncTestCaseStatusSucceeded]; + } error:NULL complete:NULL]; - [self waitForStatus:XCTAsyncTestCaseStatusSucceeded timeout:5]; + [self waitForStatus:XCTAsyncTestCaseStatusSucceeded timeout:5];*/ + + [self.manager startDownloadWithURL:self.validURL + customPath:testDirectory + delegate:nil]; + + [self waitForTimeout:kDefaultAsyncTimeout]; + + BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:testDirectory]; + XCTAssert(exists, @"Custom download directory not created"); } - (void)testOperationCorrectlyCancelled