返回顶部

收藏

iPhone开发 使用ZipArchive解压文件

更多

需要引入框架 libz.dylib;引入头文件 "ZipArchive.h"。

- (IBAction) unZipClick {
    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];

    NSString *filePath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"book_%d.zip", bookID]];
    NSString *unZipPath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"book_%d", bookID]];

    ZipArchive *zip = [[ZipArchive alloc] init];

    BOOL result;

    if ([zip UnzipOpenFile:filePath]) {
        result = [zip UnzipFileTo:unZipPath overWrite:YES];
        if (!result) {
            NSLog(@"解压失败");
        }
        else
        {
            readBtn.enabled = YES;
            NSLog(@"解压成功");
        }
        [zip UnzipCloseFile];
    }
}

标签:ios,解压缩

收藏

0人收藏

支持

0

反对

0

发表评论