iOS-NSURLSessionTask解压文件已下载
我在iOS-NSURLSessionTask解压文件已下载,ios,objective-c,nsurlsession,nsfilemanager,Ios,Objective C,Nsurlsession,Nsfilemanager,我在didfishdownloadingtourl:下载了文件,我想解压它。我当前的代码如下所示: - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location { for(NSMutableDictionary *downloadInfo in downloadingA
didfishdownloadingtourl:
下载了文件,我想解压它。我当前的代码如下所示:
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location
{
for(NSMutableDictionary *downloadInfo in downloadingArray)
{
if([[downloadInfo objectForKey:kMZDownloadKeyTask] isEqual:downloadTask])
{
if (location)
{
NSString *srcPath = location.absoluteString;
NSString *fullPathDst = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
//unzip
ZipArchive *zipArchive = [[ZipArchive alloc] init];
[zipArchive UnzipOpenFile:srcPath Password:@"pasword"];
[zipArchive UnzipFileTo:fullPathDst overWrite:YES];
[zipArchive UnzipCloseFile];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *files = [fileManager contentsOfDirectoryAtPath:fullPathDst error:&error];
NSLog(@"files: %@", files);
}
break;
}
}
}
文件
数组为空。我做错了什么?您没有写入文件名和文件类型:-
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"ZipFileName" ofType:@"zip"];
您尚未写入文件名和文件类型:-
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"ZipFileName" ofType:@"zip"];
解压将在documents目录中创建一个包含文件的文件夹。请检查一下
NSString *zipPath = [[NSBundle mainBundle] pathForResource:zipFileName ofType:@"zip"];
NSString *destinationPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
[SSZipArchive unzipFileAtPath:zipPath toDestination:destinationPath];
从文档目录获取zip文件:-
NSString *filename = @"MyZipFile.zip";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString * zipPath = [documentsDirectory stringByAppendingPathComponent:filename];
NSString *destinationPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
[SSZipArchive unzipFileAtPath:zipPath toDestination:destinationPath];
解压将在documents目录中创建一个包含文件的文件夹。请检查一下
NSString *zipPath = [[NSBundle mainBundle] pathForResource:zipFileName ofType:@"zip"];
NSString *destinationPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
[SSZipArchive unzipFileAtPath:zipPath toDestination:destinationPath];
从文档目录获取zip文件:-
NSString *filename = @"MyZipFile.zip";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString * zipPath = [documentsDirectory stringByAppendingPathComponent:filename];
NSString *destinationPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
[SSZipArchive unzipFileAtPath:zipPath toDestination:destinationPath];
您不应该使用
绝对字符串
,因为它包含一个方案(例如文件://
)。请改用path
方法。您不应该使用绝对字符串
,因为它包含一个方案(例如文件://
)。改用path
方法