SSZipArchive文件下载和解压

参考网址:

https://www.jianshu.com/p/0457e8a08c71  设置

https://www.cnblogs.com/guwudao/p/7662275.html    删除



/****************************************自己的代码***************************************************************************************************************************/


项目中,因为随时需要更新数据包(不可能发布一等到发布下一个版本),好比我自己的项目中,就包含了,HTML和一些资源文件来实现本地化存储。只要根据资源包的时间或版本(自定义的版本)来进行更新。


//下载一个文件,并写入到应用的缓存目录中。

- (void)downloadZip :(NSString*) packageUrlString{

    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

    dispatch_async(queue, ^{

        NSURL* url = [NSURLURLWithString:packageUrlString];

        NSError* error =nil;

        NSData* data = [NSDatadataWithContentsOfURL:urloptions:0error:&error];


        if(!error) {

            NSString * paths = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];

            NSString* zipPath = [pathsstringByAppendingPathComponent:@"SSZipArchive.zip"];

            NSLog(@"zipPath === %@",zipPath);

            [datawriteToFile:zipPathoptions:0error:&error];

            if(!error) {

                NSLog(@"Error saving file %@",error);

                NSLog(@"Error downloading zip file: %@", error);

            }

        }

    });

}

//我们已经把zip文件下载到/Library/Caches/zipfile.zip,现在来解压缩。

- (void)usszipArchiveFile{

    //Caches路径

    NSString * cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];

    //解压目标路径

    NSString* destinationPath = [cachesPathstringByAppendingPathComponent:@"SSZipArchive"];

    //zip压缩包的路径

    NSString* zipPath = [cachesPathstringByAppendingPathComponent:@"SSZipArchive.zip"];

    //解压

    BOOLisSuccess = [SSZipArchiveunzipFileAtPath:zipPathtoDestination:destinationPath];

    if(isSuccess) {

        NSLog(@"解压成功,文件地址在%@",destinationPath);

    }

}

//解压后的网址展示出来

//解压后的文件删除

- (void)romoveAllFile{

    NSString * documentsPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];

    NSLog(@"对比一下路径,这是要删除的目录的路径: %@",documentsPath);

    NSDirectoryEnumerator* enumerator = [[NSFileManagerdefaultManager]enumeratorAtPath:documentsPath];

    for(NSString* fileNameinenumerator) {

        [[NSFileManager defaultManager] removeItemAtPath:[documentsPath stringByAppendingPathComponent:fileName] error:nil];

    }

}


/****************************************参考代码***************************************************************************************************************************/

参考代码:


SSZipArchive文件下载和解压_第1张图片


/****************************************参考代码***************************************************************************************************************************/

你可能感兴趣的:(SSZipArchive文件下载和解压)