我想解压缩文件,但没有得到它。调试没有让我明白我的错误在哪里
我的代码:
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *pathDocumentDirectory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *directoryFilesName = @"Files";
NSString *directoryFilesPath = [[pathDocumentDirectory objectAtIndex:0] stringByAppendingPathComponent:directoryFilesName];
NSString *zipPath = downloadedItem.contentURL.path;
NSError *error = nil;
BOOL isDir = YES;
if([fileManager fileExistsAtPath:zipPath])
{
NSLog(@"\n\n\n");
NSLog(@"pathDocumentDirectory = %@", pathDocumentDirectory);
NSLog(@"directoryFilesPath = %@", directoryFilesPath);
NSLog(@"zipPath = %@", zipPath);
// Create PurchasedBooks directory
if (![fileManager fileExistsAtPath:directoryFilesPath isDirectory:&isDir]) {
[fileManager createDirectoryAtPath:directoryFilesPath withIntermediateDirectories:NO attributes:nil error:&error];
if (error) {
NSLog(@"ERROR: %@", error.description);
}
}
if (error) {
NSLog(@"ERROR: %@", error.description);
}
if ([SSZipArchive unzipFileAtPath:zipPath toDestination:directoryFilesPath overwrite:YES password:nil error:&error]) {
NSLog(@"Unziped and Moved");
} else {
NSLog(@"ERROR: Unziped and Moveed");
}
if (error) {
NSLog(@"ERROR: %@", error.description);
}
}
输出:
pathDocumentDirectory = ( "/var/mobile/Containers/Data/Application/453B1D9E-4ABD-46F6-8381-529FF9279130/Documents" ) directoryFilesPath = /var/mobile/Containers/Data/Application/453B1D9E-4ABD-46F6-8381-529FF9279130/Documents/Files zipPath = /private/var/mobile/Containers/Data/Application/453B1D9E-4ABD-46F6-8381-529FF9279130/Library/Caches/2E989856-A4BC-41CA-9109-18BC9FC1C3F8.zip ERROR: Unziped and Moveed ERROR: Error Domain=SSZipArchiveErrorDomain Code=-1 "failed to open zip file" UserInfo=0x17dda3b0 {NSLocalizedDescription=failed to open zip file}