本文介绍了解压缩内容应用内购买ios的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在应用内购买的情况下,苹果托管的内容将以.zip的形式下载。
m尝试解压缩这些内容但是已经使用zipArchive提交打开.zip文件。

  ZipArchive * za = [[ZipArchive alloc] init]; 
za.delegate = self;
NSString * path = [download.contentURL path];
if([[NSFileManager defaultManager] fileExistsAtPath:path])
{
NSLog(@File Exists:%@,path);
}
其他
{
NSLog(@文件不存在:%@,路径);
}


if([za UnzipOpenFile:path]){
if([za UnzipFileTo:dir overWrite:YES]!= NO)
{
NSLog(@解压缩数据成功);
//解压缩数据成功
//做点什么
}
其他
{
NSLog(@解压失败);
}


[za UnzipCloseFile];
}
else
{
NSLog(@unzip无法打开文件);
}

输出



文件存在:....路径..
解压缩打开文件



如果我自己捆绑.zip文件,它的工作正常

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

ZipArchive * za = [[ZipArchive alloc] init];
za.delegate = self;
if([[NSFileManager defaultManager] fileExistsAtPath:path])
{
NSLog(@File Exists:%@,path);
}
其他
{
NSLog(@文件不存在:%@,路径);
}


if([za UnzipOpenFile:path]){
if([za UnzipFileTo:dir overWrite:YES]!= NO)
{
NSLog(@解压缩数据成功);
//解压缩数据成功
//做点什么
}
其他
{
NSLog(@解压失败);
}


[za UnzipCloseFile];
}
else
{
NSLog(@unzip无法打开文件);
}

此处输出是

 文件存在:/var/mobile/Applications/B22970ED-D30A-460A-A0A1-C8458795C370/myApp.app/module.zip 

myApp [615 :907] zip文件中的63个条目
2013-10-29 18:39:46.0​​12 myApp [615:907]解压缩数据成功


解决方案

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

  NSArray * tempArrayForContentsOfDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[download.contentURL path ]错误:&错误]; 


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
解决方案

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];

这篇关于解压缩内容应用内购买ios的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-09 21:26