【问题标题】:Store file like .rar or zip in iOS [closed]在iOS中存储.rar或zip等文件[关闭]
【发布时间】:2014-05-07 10:36:43
【问题描述】:

我是 iOS 新手,想知道有没有办法将文件存储在应用程序中,如 .rar 或 zip 文件,并在需要时提取文件。

【问题讨论】:

  • 这里有 2 个问题:存储文件和提取文件。是的,您可以将文件存储在 iOS 应用程序中。见this。提取文件,网上有很多教程

标签: ios ios7


【解决方案1】:

您可以使用 ZipArchive

来做到这一点

这里是压缩和解压缩文件的完整教程。

http://transoceanic.blogspot.in/2011/07/compressuncompress-files-on.html

解压 zip 文件示例:

NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

NSString *zipFilePath = [documentsDirectory stringByAppendingPathComponent:@"myZipFileName.zip"];

NSString *output = [documentsDirectory stringByAppendingPathComponent:@"unZipDirName"];

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

if( [za UnzipOpenFile:zipFilePath] ) {
    if( [za UnzipFileTo:output overWrite:YES] != NO ) {
        //unzip data success
        //do something
    }

    [za UnzipCloseFile];
}

[za release];

【讨论】:

    【解决方案2】:

    您可以使用私有第三方类ZipArchive 来归档和提取文件。

    而且,ZipArchive 的用法可以在here 中找到。

    【讨论】:

    • 谢谢,但也请告诉我,这是以这种方式将文件存储在应用程序中的好方法吗,例如视频或图像等。
    • 当然,您可以将文件(图像或视频)存档并将其存储在应用程序的文档文件夹中。但是,随着应用的继续使用,您的应用在未来可能会消耗更多内存。
    猜你喜欢
    • 2013-03-10
    • 2012-04-04
    • 2017-12-15
    • 1970-01-01
    • 2010-12-04
    • 2011-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多