我是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"));
}
请告诉我有什么问题?
谢谢!
答案 0 :(得分: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