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

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;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • *面试心声:其实这些题本人都没怎么背,但是在上海 两周半 面了大约10家 收到差不多3个offer,总结起来就是把...
    Dove_iOS阅读 27,221评论 30 472
  • Ubuntu的发音 Ubuntu,源于非洲祖鲁人和科萨人的语言,发作 oo-boon-too 的音。了解发音是有意...
    萤火虫de梦阅读 99,648评论 9 468
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,049评论 19 139
  • 小文件下载如果文件比较小,下载方式会比较多直接用NSData的+ (id)dataWithContentsOfUR...
    醉叶惜秋阅读 892评论 0 0
  • 下面是我最近两年学习OC中的一些基础知识,对于学习OC基础知识的人可能有些帮助,拿出来分享一下,还是那句话不喜勿喷...
    小小赵纸农阅读 2,667评论 1 7