views:

98

answers:

1

Hi, everyone,

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.

+1  A: 

You can use this method:

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

More here and 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

More here

vodkhang
@vodkhang, thank you for your reply. I would like to ask one more question, is it almost the same for iPhone to download the file from the server? (e.g. download the .vcf from CardDav and .iCal from CalDav or simple download a text file from a web server)
Questions
I think it is the same. It just data, the only difference you may need to care is how do you translate that data to an appropriate one (text or .vcf)
vodkhang
@vodkhang, thank you for your reply. It is very useful.
Questions