下载并保存zip文件到iphone [英] download and save zip file to iphone

查看:312
本文介绍了下载并保存zip文件到iphone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从网络下载zip文件,但无法弄清楚如何可能

i want to download the zip file from web but unable to figure out that how it is possible

我可以下载image / text / xml文件,但无法下载一个zip文件

i can download image /text/xml file but unable to download a zip file

有人可以指导我如何从网上下载zip文件?

Can someone guide me how to download zip files from web?

谢谢

推荐答案

如果您使用 NSURLConnection ,它的工作方式完全相同,无论哪种类型文件有。

If you're using NSURLConnection, it works exactly the same way no matter which type the file has.

示例:(打开我的头,不保证它的工作这样你应该明确地执行错误检查)

Example: (typed off of my head, no guarantee that it works this way and you should obviously implement error checking)

- (void) download
{
    self.loadedData = [NSMutableData data];         // make 'loadedData' a property of the class

    NSURL *url = [NSURL URLWithString:@"http://..."];
    NSMutableURLRequest  *urlRequest = [NSMutableURLRequest requestWithURL:url
                                                               cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
                                                           timeoutInterval:20.0];
    [urlRequest setValue:@"Optional User Agent" forHTTPHeaderField:@"User-Agent"];

    // shoot it off
    NSURLConnection *mainConnection = [NSURLConnection connectionWithRequest:urlRequest delegate:self];
    if (nil == mainConnection) {
        NSLog(@"Could not create the NSURLConnection object");
    }
}

然后您必须处理代理方法中的传入数据,例如要保存数据:

Then you must handle the incoming data in the delegate methods, e.g. to just save your data:

- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [loadedData appendData:data];
}

查看其他委托方法和实施它们,你应该处理认证挑战和失败的响应。您也可以设置:

Take a look at the other delegate methods and implement them, you should deal with authentification challenges and fail responses. You can also for example set:

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

连接:didReceiveResponse:并设置至 NO 再次在 connectionDidFinishLoading:

这篇关于下载并保存zip文件到iphone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆