Asynchronous url requests inside dispatch_async

前端 未结 3 1563
悲&欢浪女
悲&欢浪女 2020-12-28 10:35

I am trying to implement asynchronous url requests in a particular function, I want all these requests to complete and then do a particular action but the action precedes th

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-28 11:37

    First Configure run loop.

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];
        [NSURLConnection connectionWithRequest:request delegate:self];
        while(!self.finished) {
            [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
        }
    });
    

    Try this

提交回复
热议问题