问题
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
回答1:
Do not try to unzip package. This is just a folder. You can look at the content using this code:
NSArray *tempArrayForContentsOfDirectory =[[NSFileManager defaultManager] contentsOfDirectoryAtPath:[download.contentURL path] error:&error];
来源:https://stackoverflow.com/questions/19660317/unzip-contents-in-app-purchase-ios