0

我是 Objective-C 的初学者,需要你的帮助。

在 iOS 中,我需要解压缩使用 AES 256 方法加密的文件。

在这个答案中https://stackoverflow.com/a/10489305/2822169 Nathan Moinvaziri 写了关于使用这个库的文章:https ://github.com/nmoinvaz/minizip

我正在尝试这样做:

#import "unzip.h"

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path = [paths objectAtIndex:0];
    NSString *zipPath = [path stringByAppendingPathComponent:@"myFile.zip"];   // this file exists there 100%

    unzFile *uf = unzOpen64((__bridge const void *)(zipPath));  // but here uf returns 0x00000000
    unzOpenCurrentFilePassword(uf, (__bridge const void *)(@"myPassword"));
}

请告诉我有什么问题吗?

谢谢!

4

1 回答 1

0

这可能是unZip 的最佳库。

下载它并将其添加到您的项目中,然后,

#import "ZipArchive.h" // in your ".m" file

并编写以下代码

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

NSString *basepath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"resources.zip"]];
    [self.responseData  writeToFile:basepath  atomically:YES];

    ZipArchive* za = [[ZipArchive alloc] init];
    if( [za UnzipOpenFile:[NSString stringWithFormat:@"%@",basepath]] )
    {
        BOOL ret = [za UnzipFileTo:[GeneralClass getDocumentDirectory]  overWrite:YES];
        if(!ret)
            NSLog(@"problem while loading data..");
        [za UnzipCloseFile];
    }

    NSFileManager *fileManager = [NSFileManager defaultManager];
    [fileManager removeItemAtPath:basepath error:NULL];

    basepath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"response.txt"]];
    NSString* response = [NSString stringWithContentsOfFile:basepath encoding:NSUTF8StringEncoding error:NULL];
    NSMutableDictionary *detailRequestData = [[NSMutableDictionary alloc] init];
    detailRequestData = [response JSONValue];
    [fileManager removeItemAtPath:basepath error:NULL];

 NSLog(@"I Got Data%@", detailRequestData); /// see in consol 
于 2013-09-27T06:46:25.163 回答