【问题标题】:iPhone - Download file from the internet and save to documents direcoryiPhone - 从 Internet 下载文件并保存到文档目录
【发布时间】:2012-08-03 20:40:32
【问题描述】:

我正在尝试使用 NSUrlConnection 下载文件,将文件保存到文档目录,然后在 web 视图中打开它。

我正在使用代码:

- (IBAction)down:(id)sender {
// create the request
url = [[NSURL alloc]initWithString:urlbox.text];
NSLog(@"%@",url);

NSURLRequest *theRequest=[NSURLRequest requestWithURL:url
                                          cachePolicy:NSURLRequestUseProtocolCachePolicy
                                      timeoutInterval:60.0];
NSURLConnection *theConnection;
theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {

    NSMutableData *receivedData;
    receivedData=[NSMutableData data];

}

下载文件。如果有人可以给我一些代码来保存文件并在 web 视图中打开它,那就太好了。

谢谢

【问题讨论】:

  • 你已经尝试了什么?你有什么问题吗?这不是按需代码服务。
  • 我听说这个“google”网站有一个很棒的代码库

标签: iphone xcode uiwebview nsurlconnection nsdocumentdirectory


【解决方案1】:

看看MGPRemoteAssetController,这是我使用的基于NSURLConnection的插件。

更重要的是,您可以跟踪 MGPRemoteAssetDownloader 的工作方式。这是一个很棒的示例代码。

【讨论】:

    【解决方案2】:

    获取 Vandad Nahavandipoor (O'Reilly) 所著的《iOS 编程手册》一书,其中包含示例和代码,可以完全按照您的要求进行操作。 Matt Neuburg(也是 O'Reilly)的“Programming iOS 5”也很有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-10
      • 1970-01-01
      • 1970-01-01
      • 2016-07-27
      • 2011-01-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多