nsurlconnection 默认是什么?同步还是异步?
nsurlconnection is by default what ? Synchronous or asynchronous?
NSURLRequest *req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://google.com"]];
NSURLConnection * connect = [[NSURLConnection alloc] initWithRequest:req delegate:self];
[connect start];
这是同步的还是异步的??? NSURLConnection 默认是 which 1 ??
当您以这种方式实例化它时,您正在调用异步的、基于委托的实现。
请注意,如果您调用 initWithRequest:delegate:
,则不应调用 start
。仅当您使用 NO
为该最终参数调用 initWithRequest:delegate:startImmediately:
时才使用它。没有该 startImmediately
参数的再现会自动为您启动连接。
NSURLConnection API 可以是同步的或异步的,具体取决于您如何使用它,而 NSURLSession API 是异步的。
上面的例子是异步的。
这取决于你在 NSURLConnection 中调用的方法。但是大多数方法都是异步相关的。除了 sendSynchronousRequest:returningResponse:error:
正在同步加载数据
+ sendSynchronousRequest:returningResponse:error:
异步加载数据
+ connectionWithRequest:delegate:
– initWithRequest:delegate:
– initWithRequest:delegate:startImmediately:
+ sendAsynchronousRequest:queue:completionHandler:
– start
NSURLRequest *req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://google.com"]];
NSURLConnection * connect = [[NSURLConnection alloc] initWithRequest:req delegate:self];
[connect start];
这是同步的还是异步的??? NSURLConnection 默认是 which 1 ??
当您以这种方式实例化它时,您正在调用异步的、基于委托的实现。
请注意,如果您调用 initWithRequest:delegate:
,则不应调用 start
。仅当您使用 NO
为该最终参数调用 initWithRequest:delegate:startImmediately:
时才使用它。没有该 startImmediately
参数的再现会自动为您启动连接。
NSURLConnection API 可以是同步的或异步的,具体取决于您如何使用它,而 NSURLSession API 是异步的。
上面的例子是异步的。
这取决于你在 NSURLConnection 中调用的方法。但是大多数方法都是异步相关的。除了 sendSynchronousRequest:returningResponse:error:
正在同步加载数据
+ sendSynchronousRequest:returningResponse:error:
异步加载数据
+ connectionWithRequest:delegate:
– initWithRequest:delegate:
– initWithRequest:delegate:startImmediately:
+ sendAsynchronousRequest:queue:completionHandler:
– start