AFN 다운로드 파일 압축 해제 파일 및 정지점 전송

파일 다운로드 및 정지점 전송:http://www.cnblogs.com/qingche/p/5362592.html
압축 해제 파일 다운로드: 파일 다운로드 용 제3자 라 이브 러 리: AFNetWorking 압축 해제 파일 용 제3자 라 이브 러 리: SSZipArchive
#import "DownloadFileManager.h"
#import "SSZipArchive.h"
#import "PCH.h"
@interface DownloadFileManager ()
@end
@implementation DownloadFileManager
-(void)download
{
    //1.       
    AFHTTPSessionManager *manager =[AFHTTPSessionManager manager];
    
    NSURL *url = [NSURL URLWithString:@"http://192.168.2.189:8080/DSFA/news/apptest.zip"];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    //2.    
    /*
          :    
          :progress      downloadProgress
          :destination   (    )
         
     targetPath:      
     response:     
          :completionHandler          
     filePath:       
     */
    
    /*
          :    
          :    
     downloadProgress.completedUnitCount :       
     downloadProgress.totalUnitCount:      
          :destination  , block     (NSURL  ),                
     targetPath:         tmp,       
     response:     
          :completionHandler       
     response:     
     filePath:       , destination      
     error:    
     */
    NSURLSessionDownloadTask *download = [manager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) {
        
        //      
        //completedUnitCount          
        //totalUnitCount             
        NSLog(@"%f",1.0 *downloadProgress.completedUnitCount / downloadProgress.totalUnitCount);
        
    } destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
        /**
         * 1:1:    :NSUrl *url = [NSUrl urlWithString:path];         2:    file      url,NSUrl *url = [NSURL fileURLWithPath:fullPath];
         2:             
         *
         */
        NSString *fullPath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:response.suggestedFilename];
        
        NSLog(@"targetPath:%@",targetPath);
        NSLog(@"fullPath:%@",fullPath);
        
        return [NSURL fileURLWithPath:fullPath];
    } completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
        /**
         *filePath:          
         */
        NSLog(@"%@",filePath);
        NSString *imgFilePath = [filePath path];//  NSURL  NSString
       
        NSString *path =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
        [self releaseZipFilesWithUnzipFileAtPath:imgFilePath Destination:path];
    }];
    
    
    //3.  Task
    [download resume];
}
//   
- (void)releaseZipFilesWithUnzipFileAtPath:(NSString *)zipPath Destination:(NSString *)unzipPath{
    NSError *error;
    if ([SSZipArchive unzipFileAtPath:zipPath toDestination:unzipPath overwrite:YES password:nil error:&error delegate:self]) {
        NSLog(@"success");
        NSLog(@"unzipPath = %@",unzipPath);
    }else {
        NSLog(@"%@",error);
    }
}
#pragma mark - SSZipArchiveDelegate
- (void)zipArchiveWillUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo {
    NSLog(@"    。");
}
- (void)zipArchiveDidUnzipArchiveAtPath:(NSString *)path zipInfo:(unz_global_info)zipInfo unzippedPath:(NSString *)unzippedPath{
    NSLog(@"    !");
}

좋은 웹페이지 즐겨찾기