ASIHTTPRequest不下载zip文件

时间:2013-09-02 13:26:29

标签: iphone ios url zip asihttprequest

解压缩后,我必须从网址下载一个zip文件。有问题的文件我把它放在Documents文件夹中。它没有完全下载。 这是代码:

 NSURL *urltoZip = [NSURL URLWithString: urlZip]; 

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

 NSString *filePathAndDirectory1 = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"/ZipPackages"]];

if (![[NSFileManager defaultManager] fileExistsAtPath:filePathAndDirectory1])
    [[NSFileManager defaultManager] createDirectoryAtPath:filePathAndDirectory1 withIntermediateDirectories:NO attributes:nil error:&error];

 NSString *filePathAndDirectory = [filePathAndDirectory1 stringByAppendingPathComponent:[NSString stringWithFormat:@"/%@", self.nomePackage]];


if (![[NSFileManager defaultManager] fileExistsAtPath:filePathAndDirectory])
    [[NSFileManager defaultManager] createDirectoryAtPath:filePathAndDirectory withIntermediateDirectories:NO attributes:nil error:&error];


NSLog(@"fileName zip %@", filePathAndDirectory);
/*  fileName zip   /var/mobile/Applications/5256198E-72FC-4054-BFD3-BC1600BDC01C/Documents/ZipPackages/HtmlInfo */

ASIHTTPRequest *requestZip = [ASIHTTPRequest requestWithURL:urltoZip];
[requestZip setDownloadDestinationPath:filePathAndDirectory]; //in this path is not saved anything
[requestZip startSynchronous];

response =[requestZip responseString];

  NSLog(@" response zip  %@", response);
  /*response zip 

     <!DOCTYPE html>

     <html lang="en">

      <head><meta charset="utf-8" /><title>

       ..........

       </footer>

      </form>

    </body>

    </html>*/

在“文档”文件夹中没有该文件的跟踪。我该怎么办?

1 个答案:

答案 0 :(得分:0)

在您的代码中:

NSString *filePathAndDirectory1 = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"/ZipPackages"]];

&#34; /&#34;使用&#34; stringByAppendingPathComponent时不需要:&#34; 将代码更改为:

 NSString *filePathAndDirectory1 = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"ZipPackages"]];

再试一次它现在可能有效。