网上下载压缩文件本地解压加载

1.使用SSZipArchive

pod 'SSZipArchive'           #zip解压压缩

2.拷贝文件到沙盒


+(BOOL) copyFileToDocument:(NSString*)FileName {
    
    NSString *appFileName =[self fullpathOfFilename:FileName];
    NSFileManager *fm = [NSFileManager defaultManager];
    //判断沙盒下是否存在
    
    BOOL isExist = [fm fileExistsAtPath:appFileName];
    if (!isExist)   //不存在,把工程的文件复制document目录下
    {
        //获取工程中文件
        NSString *backupDbPath = [[NSBundle mainBundle]
                                  
                                  pathForResource:FileName
                                  
                                  ofType:@""];
        //这一步实现数据库的添加,  
        
        // 通过NSFileManager 对象的复制属性,把工程中数据库的路径复制到应用程序的路径上  
        
        [fm copyItemAtPath:backupDbPath toPath:appFileName error:nil];
        return isExist;
    } else {
        return  isExist; //已经存在
    }
}

3.路径相关

+(NSString *)documentsPath {
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    
    return [paths objectAtIndex:0];
    
}
+ (NSString *)emojiPathWithName:(NSString *)name {
    NSString *path = [NSString stringWithFormat:@"%@/Emotions/%@",[self documentsPath],name];
    return path;
}

+ (NSString *)emojiPath {
    NSString *path = [NSString stringWithFormat:@"%@/Emotions",[self documentsPath]];
    return path;
}

+ (NSArray *)enumeratorListWithEmojiPath {
    NSString *path = [self emojiPath]; // 要列出来的目录

    NSFileManager *myFileManager=[NSFileManager defaultManager];

    NSDirectoryEnumerator *myDirectoryEnumerator;

    myDirectoryEnumerator=[myFileManager enumeratorAtPath:path];

    //列举目录内容,可以遍历子目录

    NSLog(@"用enumeratorAtPath:显示目录%@的内容:",path);
    NSMutableArray *array = [NSMutableArray array];
    while((path=[myDirectoryEnumerator nextObject])!=nil)
        
    {
        if (![path containsString:@"/"] && ![path containsString:@"qq"]) {
            [array addObject:path];
             NSLog(@"%@",path);
        }
    }
    return array;
}

你可能感兴趣的:(网上下载压缩文件本地解压加载)