2

apple hosted contents are downloading as .zip in case of in-app purchase. m trying to unzip these contents but filed to open .zip file with zipArchive.

ZipArchive* za = [[ZipArchive alloc] init];
za.delegate = self;
NSString *path = [download.contentURL path];
if([[NSFileManager defaultManager] fileExistsAtPath:path])
{
    NSLog(@"File Exists: %@", path);
}
else
{
    NSLog(@"file not exists: %@", path);
}


if( [za UnzipOpenFile:path] ) {
    if( [za UnzipFileTo:dir overWrite:YES] != NO )
    {
        NSLog(@"unzip data success");
        //unzip data success
        //do something
    }
    else
    {
        NSLog(@"unzip failed");
    }


    [za UnzipCloseFile];
}
else
{
    NSLog(@"unzip can't open file");
}

output is

File Exists:....path.. unzip cant open file

Rather its working fine if I bundle a .zip file own

path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"module.zip"];

ZipArchive* za = [[ZipArchive alloc] init];
za.delegate = self;
if([[NSFileManager defaultManager] fileExistsAtPath:path])
{
    NSLog(@"File Exists: %@", path);
}
else
{
    NSLog(@"file not exists: %@", path);
}


if( [za UnzipOpenFile:path] ) {
    if( [za UnzipFileTo:dir overWrite:YES] != NO )
    {
        NSLog(@"unzip data success");
        //unzip data success
        //do something
    }
    else
    {
        NSLog(@"unzip failed");
    }


    [za UnzipCloseFile];
}
else
{
    NSLog(@"unzip can't open file");
}

here out put is

File Exists: /var/mobile/Applications/B22970ED-D30A-460A-A0A1-C8458795C370/myApp.app/module.zip

myApp[615:907] 63 entries in the zip file
2013-10-29 18:39:46.012 myApp[615:907] unzip data success
4

1 回答 1

13

不要尝试解压缩包。这只是一个文件夹。您可以使用以下代码查看内容:

NSArray *tempArrayForContentsOfDirectory =[[NSFileManager defaultManager] contentsOfDirectoryAtPath:[download.contentURL path] error:&error];
于 2013-10-29T14:12:49.830 回答