本文介绍了在NSRunLoop上,需要进行澄清的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我

    Logger *logger = [Logger new];

    NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];

    __unused NSURLConnection *conn = [[NSURLConnection alloc]
            initWithRequest:request delegate:logger startImmediately:YES];

...没有任何反应。直到i

... nothing happens. Delegate methods are not called until i

[[NSRunLoop currentRunLoop]run];

我以为 startImmediately:YES 会做到这一点

推荐答案

异步回调需要一个NSRunLoop。见:

async callbacks require an NSRunLoop. See:

命令行应用程序默认情况下没有NSRunLoop - gui apps do。

command line apps don't have an NSRunLoop by default - gui apps do.

从文档中:

initWithRequest:delegate:
返回初始化的URL连接,并开始加载URL请求的数据。

initWithRequest:delegate:Returns an initialized URL connection and begins to load the data for the URL request.

- (id)initWithRequest:(NSURLRequest *)request delegate:(id < NSURLConnectionDelegate >)delegate



这篇关于在NSRunLoop上,需要进行澄清的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 08:47