【问题标题】:download .zip or .doc file on iphone在 iPhone 上下载 .zip 或 .doc 文件
【发布时间】:2011-02-17 22:39:33
【问题描述】:

我想通过网络服务请求从服务器下载 .zip 或 .pdf 或 .doc 文件到 iphone 并且 web 服务部署在 IIS 上。

我对此一无所知

【问题讨论】:

标签: iphone objective-c xcode ios4 download


【解决方案1】:

这段代码下载一个 pdf 并将其保存到一个临时位置

NSData *pdfData = [NSData  dataWithContentsOfURL:pdfURL];
NSString *fileName = [[pdfURL path] lastPathComponent];
NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:fileName];
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
NSError *writeError = nil;
[pdfData writeToURL: fileURL options:0 error:&writeError];
if( writeError) {
   NSLog(@" Error in writing file %@' : \n %@ ", filePath , writeError );
                                            return;
}
NSLog(@"%@",fileURL);

【讨论】:

    【解决方案2】:

    使用 NSURLConnection 或更好的 ASIHTTPRequest 将文件下载为您写入文件的 NSData。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-22
      • 1970-01-01
      • 1970-01-01
      • 2017-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多