How to upload a file using NSURLConnection?

I want to ask a question about goal C. I want to download the .vcf file from the server (CardDav server) in the iPhone application. After I read the Apple Developer API and library, I found that I should use the NSURLConnection class . However, I do not know how to run the program.

So I want to ask if someone can give me some tutorial or link to the site (I mean an example) for me? Thank you very much.

0
source share
1 answer

You can use this method:

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

More details here and delegate:

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

A delegate is an object that can respond to the two methods of receiving data above. If you want to do asynchronous, you must use a delegate. If you do not, you can simply do:

 + (NSData *)sendSynchronousRequest:(NSURLRequest *)request returningResponse:(NSURLResponse **)response error:(NSError **)error [More here][2] 

Or you can just do this for some data:

 + (id)dataWithContentsOfURL:(NSURL *)aURL 

More here

+2
source

All Articles