zipArchive unzip to document folder on iOS

孤街醉人 提交于 2019-12-08 01:40:55

问题


I'm using ZipArchive to unzip but its unzipping the contents of the zip to a subdirectory of my documents named after the zip file instead of directly into my documents folder. Does anyone know what I can change to make sure its saves to the directory that I want?

-(void) unZipUpdateArchiveAtPath: (NSString *)zipPath {
NSLog(@"UNZIP Update PATH: %@", zipPath);
ZipArchive *zipArchive = [[ZipArchive alloc] init];
if ([zipArchive UnzipOpenFile:zipPath])
{
    if ([zipArchive UnzipFileTo:[self documentDirectory]  overWrite:YES])
    {
        NSLog(@"Archive unzip success");
        [zipArchive UnzipCloseFile];
    }
    else
    {
        NSLog(@"Failure to unzip archive");
    }
}
else
{
    NSLog(@"Failure to open archive");
}
}

#pragma mark - Application's Documents directory
-(NSString *)documentDirectory
{
    NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    NSString *documentDirectory = [documentDirectories objectAtIndex:0];
    NSLog(@"docDirectory IS  %@", documentDirectory);
    return documentDirectory;
}

回答1:


You need to append your custom path to your documents directory.

[zipArchive UnzipFileTo:[[self documentDirectory] stringByAppendingPathComponent:@"My folder"] overWrite:YES];


来源:https://stackoverflow.com/questions/10725176/ziparchive-unzip-to-document-folder-on-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!