1

解压缩后,我必须从 url 下载一个 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>*/

在 Documents 文件夹中没有文件的痕迹。我能怎么做?

4

1 回答 1

0

输入您的代码:

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

使用“stringByAppendingPathComponent:”时不需要“/”,将代码更改如下:

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

再试一次它现在可能工作。

于 2014-08-13T06:57:28.653 回答