# import "AFHTTPRequestOperationManager.h"
-(void)downloadUrl:(NSString*)url toPath:(NSString*)path
success :(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure :(void (^)(AFHTTPRequestOperation *operation, NSError *error ))failure
progress:(void (^)(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead))progress
{
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
AFHTTPRequestOperation *op = [manager GET:url
parameters:nil
success:success
failure:failure];
[op setDownloadProgressBlock:progress];
op.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];
}
NSString *path = [NSTemporaryDirectory() stringByAppendingPathComponent:@"tmp.bin"];
[self downloadUrl:url toPath:path
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"DL: success");
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"DL: failed %@", error);
}
progress:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
NSLog(@"DL: progress %d", (int)(100 * totalBytesRead / totalBytesExpectedToRead));
}];
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme