How to make program wait for asynchronous NSURLConnection to finish before proceeding with next command?

后端 未结 6 1779
日久生厌
日久生厌 2021-02-01 09:10

How can I make my program wait for an asynchronous NSURLConnection to finish before going to the next line of code?

SetDelegate *sjd= [SetDelegate alloc];
NSURLC         


        
6条回答
  •  北恋
    北恋 (楼主)
    2021-02-01 09:40

    If you really want it to wait, why use an asynchronous call at all? Use a synchronous call instead:

    NSURLResponse* response = nil;
    NSData* data = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil]
    

    This approach will block the thread it's executed, so you should be sure you want to do it! Did I mention that it will block? :)

提交回复
热议问题