-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgraded to AFNetworking 2.2.3, updated README.md
- Loading branch information
Showing
5 changed files
with
44 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-32.2 KB
(29%)
....xcodeproj/project.xcworkspace/xcuserdata/eric.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
/* | ||
File: EWCacheManager.h | ||
Version: 1.1 | ||
Version: 1.2 | ||
Created: 2013-12-06 | ||
Updated: 2014-03-14 | ||
Updated: 2014-04-24 | ||
Author: Eric Bailey <[email protected]> | ||
Electric Wizardry, LLC <http://electric-wizardry.com> | ||
|
@@ -32,8 +32,8 @@ | |
|
||
#import <Foundation/Foundation.h> | ||
|
||
@class AFHTTPClient; | ||
@class AFHTTPRequestOperation; | ||
@class AFHTTPRequestOperationManager; | ||
|
||
@class EWCacheManager; | ||
@protocol EWCacheManagerDelegate | ||
|
@@ -58,7 +58,7 @@ | |
|
||
@property(nonatomic, weak) id<EWCacheManagerDelegate> delegate; | ||
|
||
@property(nonatomic, strong) AFHTTPClient *downloadClient; | ||
@property(nonatomic, strong) AFHTTPRequestOperationManager *downloadClient; | ||
@property(nonatomic, strong) NSURL *baseURL; | ||
|
||
@property(readonly) float fileProgress; | ||
|
@@ -109,21 +109,27 @@ | |
- (void)deleteFileInCache:(NSString *)filename; | ||
|
||
/** | ||
* Description | ||
* Initiates a download request with the specified request and filename, | ||
* executing success() and failure() as appropriate, if defined. | ||
* | ||
* @param request request description | ||
* @param filename filename description | ||
* @param success success description | ||
* @param request The URL request to make. | ||
* @param filename The filename where the data should be downloaded. | ||
* @param success The block to execute upon sucessfully downloading the | ||
* requested file. | ||
* @param failure The block to execute upon failure (lost connection, data | ||
* corruption, IO error, etc). | ||
*/ | ||
- (void)downloadFileWithRequest:(NSURLRequest *)request | ||
filename:(NSString *)filename | ||
success:(void (^)(AFHTTPRequestOperation *operation, | ||
id responseObject))success; | ||
id responseObject))success | ||
failure:(void (^)(AFHTTPRequestOperation *operation, | ||
NSError *error))failure; | ||
|
||
/** | ||
* Description | ||
* Returns the name of the file currently being downloaded. | ||
* | ||
* @return return value description | ||
* @return The filename. | ||
*/ | ||
- (NSString *)nameOfFileCurrentlyDownloading; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
File: EWCacheManager.m | ||
Version: 1.1 | ||
Created: 2013-12-06 | ||
Updated: 2014-03-14 | ||
Updated: 2014-04-24 | ||
Author: Eric Bailey <[email protected]> | ||
Electric Wizardry, LLC <http://electric-wizardry.com> | ||
|
@@ -31,11 +31,11 @@ this software and associated documentation files (the "Software"), to deal in | |
*/ | ||
|
||
#import "EWCacheManager.h" | ||
#import <AFNetworking/AFHTTPClient.h> | ||
#import <AFNetworking/AFNetworking.h> | ||
#import <AFNetworking/AFHTTPRequestOperation.h> | ||
#import "NSFileManager+DirectoryLocations.h" | ||
|
||
@implementation EWCacheManager | ||
@synthesize baseURL = _baseURL; | ||
@synthesize fileProgress = _fileProgress; | ||
@synthesize queueProgress = _queueProgress; | ||
|
||
|
@@ -48,7 +48,8 @@ + (id)sharedManager { | |
|
||
- (id)init { | ||
if (self = [super init]) { | ||
path = [[NSFileManager defaultManager] applicationSupportDirectory]; | ||
path = [NSSearchPathForDirectoriesInDomains( | ||
NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; | ||
|
||
_fileProgress = 0.0f; | ||
_requestedFilesCount = 0; | ||
|
@@ -59,7 +60,9 @@ - (id)init { | |
- (void)downloadFileWithRequest:(NSURLRequest *)request | ||
filename:(NSString *)filename | ||
success:(void (^)(AFHTTPRequestOperation *operation, | ||
id responseObject))success { | ||
id responseObject))success | ||
failure:(void (^)(AFHTTPRequestOperation *operation, | ||
NSError *error))failure { | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
self.requestedFilesCount++; | ||
AFHTTPRequestOperation *operation = | ||
|
@@ -95,7 +98,7 @@ - (void)downloadFileWithRequest:(NSURLRequest *)request | |
error:error]; | ||
}]; | ||
|
||
[self.downloadClient enqueueHTTPRequestOperation:operation]; | ||
[self.downloadClient.operationQueue addOperation:operation]; | ||
}); | ||
} | ||
|
||
|
@@ -137,29 +140,24 @@ - (void)setRequestedFilesCount:(NSUInteger)requestedFilesCount { | |
_requestedFilesCount = requestedFilesCount; | ||
} | ||
|
||
@synthesize baseURL = _baseURL; | ||
- (void)setBaseURL:(NSURL *)baseURL { | ||
_baseURL = baseURL; | ||
|
||
_downloadClient = [[AFHTTPClient alloc] initWithBaseURL:_baseURL]; | ||
[_downloadClient registerHTTPOperationClass:[AFHTTPRequestOperation class]]; | ||
[_downloadClient.operationQueue setMaxConcurrentOperationCount:1]; | ||
} | ||
|
||
@synthesize downloadClient = _downloadClient; | ||
- (AFHTTPClient *)downloadClient { | ||
- (AFHTTPRequestOperationManager *)downloadClient { | ||
NSAssert(_baseURL, @"No base URL set."); | ||
|
||
if (!_downloadClient) { | ||
_downloadClient = | ||
[[AFHTTPRequestOperationManager alloc] initWithBaseURL:_baseURL]; | ||
[_downloadClient.operationQueue setMaxConcurrentOperationCount:1]; | ||
} | ||
|
||
return _downloadClient; | ||
} | ||
|
||
@synthesize requestedFilesCount = _requestedFilesCount; | ||
- (NSUInteger)requestedFilesCount { | ||
if (self.downloadClient.operationQueue.operationCount > 0) { | ||
return _requestedFilesCount; | ||
} | ||
|
||
return 0; | ||
return (self.downloadClient.operationQueue.operationCount > 0) | ||
? _requestedFilesCount | ||
: 0; | ||
} | ||
|
||
- (NSString *)nameOfFileCurrentlyDownloading { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters