How to download a file by using NSURLConnection?

僤鯓⒐⒋嵵緔 提交于 2019-12-02 13:16:47

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!