CocoaPods trunk is moving to be read-only. Read more on the blog, there are 19 months to go.
TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by Dalton Claybrook.
A collection of classes useful for fetching and persisting file data. Built on top of NSURLSession.
Initialization & Configuration:
self.fileManager = [[SFSFileManager alloc] init];
self.fileManager.usesEncryptionByDefault = YES;
self.fileManager.diskSizeLimit = 512 * 1024 * 1024; // 512 MB
Simplest Fetch:
NSURL *url = [NSURL URLWithString:@"http://placekitten/600/500"];
[self.fileManager fetchFileDataAtURL:url withCompletion:^(NSURL *fileURL, NSError *error) {
// data fetched using '[url absoluteString]' as the identifier
// and 'SFSFileManagerDefaultFileGroup' as the file group
}];
Complex Fetch:
NSURL *url = [NSURL URLWithString:@"http://myapi.com/users"];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
[request setValue:<#auth string#> forHTTPHeaderField:@"Authorization"];
SFSFileFetchRequest *request = [SFSFileFetchRequest request];
request.urlRequest = urlRequest;
request.identifier = @"12345";
request.fileGroup = @"userDataGroup";
request.encryptionPolicy = SFSFileFetchRequestEncryptionPolicyUseEncryption;
request.taskPriority = SFSFileFetchRequestTaskPriorityHigh;
__typeof__(self) __weak weakSelf = self;
id<SFSTask> task = [self.fileManager fetchFileDataUsingFetchRequest:request withCompletion:^(NSURL *fileURL, NSError *error) {
[weakSelf useFileAtURL:fileURL error:error];
}];
// Some time later...
if ([task isRunning])
{
[task ignoreResults]; //will cause the above completion block to not be called, but will not cancel the request.
// or
[task cancelRequest];
}
Image Manager:
// using 'nil' causes a file manager to be created for you.
self.imageManager = [[SFSImageManager alloc] initWithFileManager:nil];
NSURL *url = [NSURL URLWithString:@"http://placekitten/600/500"];
__typeof__(self) __weak weakSelf = self;
[self.imageManager fetchImageAtURL:url withCompletion:^(UIImage *image, NSError *error) {
// completion is executed on the main thread.
weakSelf.imageView.image = image;
}];
By far, the easiest way to integrate SpaceFactoryNetworking is using CocoaPods:
# Example Podfile
pod 'SpaceFactoryNetworking'
Otherwise, you can clone this repo, and import files from the 'SpaceFactoryNetworking/Core' folder.
You are welcome to submit pull requests to this project. If you are considering doing so, please reach out to me at [email protected]. I'd like to touch base.