Does -dataWithContentsOfURL: of NSData work in a background thread?

前端 未结 7 1429
南笙
南笙 2020-12-30 05:39

Does -dataWithContentsOfURL: of NSData work in a background thread?

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-30 06:29

    No, it doesn't.

    In order to get data from URL asynchronously you should use the NSURLRequest and NSURLConnection approach.

    You will have to implement the NSURLConnectionDelegate methods:

    -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;
    -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
    -(void)connectionDidFinishLoading:(NSURLConnection *)connection;
    -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error;
    

提交回复
热议问题