本文介绍了如何使用NSURLConnection下载文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一个关于目标C的问题。我想从iPhone应用程序中的服务器(CardDav服务器)下载.vcf文件。在我阅读了Apple Developer的API和库之后,我发现我应该使用。但是,我不知道如何启动该程序。

I want to ask a question about the objective C. I want to download a .vcf file from a server (CardDav server) in iPhone application. After I read the API and library of the Apple Developer, I found that I should use the NSURLConnection Class. However, I don't know how to start the program.

因此,我想问一下,任何人都可以给我一些教程或网站参考(我的意思是这个例子)我?非常感谢。

Therefore, I want to ask can anyone give me some tutorial or website reference (I mean the example) for me? Thank you very much.

推荐答案

您可以使用此方法:

- (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate startImmediately:(BOOL)startImmediately


and delegate:

More hereand the delegate:

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response

- (void)connectionDidFinishLoading:(NSURLConnection *)connection

委托是一个对象,可以响应上述两种方法来接收数据。如果要进行异步,则必须使用委托。如果你不这样做,你可以这样做:

The delegate is an object that can respond to 2 above methods to receive the data. If you want to do asynchronous, you have to use delegate. If you don't, you can just do:

+ (NSData *)sendSynchronousRequest:(NSURLRequest *)request returningResponse:(NSURLResponse **)response error:(NSError **)error

[More here][2]

或者你可以这样做一些数据:

Or you can just do like this for some data:

+ (id)dataWithContentsOfURL:(NSURL *)aURL

这篇关于如何使用NSURLConnection下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 13:24
查看更多