asihttp 源码分析 之三 startRequest 各种回调
SELdidStartSelector;
SEL didReceiveResponseHeadersSelector;SEL willRedirectSelector;
SEL didFinishSelector;
SELdidFailSelector;
SEL didReceiveDataSelector;各种SEL 的调用时机。
1: SEL didStartSelector;
- (void)startRequest 一开始就调用了requestStarted。
[self performSelectorOnMainThread:@selector(requestStarted) withObject:nil waitUntilDone:[NSThread isMainThread]];
/* ALWAYS CALLED ON MAIN THREAD! */ - (void)requestStarted { if ([self error] || [self mainRequest]) { return; } if (delegate && [delegate respondsToSelector:didStartSelector]) { [delegate performSelector:didStartSelector withObject:self]; } if (queue && [queue respondsToSelector:@selector(requestStarted:)]) { [queue performSelector:@selector(requestStarted:) withObject:self]; } #if NS_BLOCKS_AVAILABLE if(startedBlock){ startedBlock(); } #endif }
2: SEL didReceiveResponseHeadersSelector;
/* ALWAYS CALLED ON MAIN THREAD! */ - (void)requestReceivedResponseHeaders:(NSMutableDictionary *)newResponseHeaders { if ([self error] || [self mainRequest]) { return; } if (delegate && [delegate respondsToSelector:didReceiveResponseHeadersSelector]) { [delegate performSelector:didReceiveResponseHeadersSelector withObject:self withObject:newResponseHeaders]; } if (queue && [queue respondsToSelector:@selector(request:didReceiveResponseHeaders:)]) { [queue performSelector:@selector(request:didReceiveResponseHeaders:) withObject:self withObject:newResponseHeaders]; } #if NS_BLOCKS_AVAILABLE if(headersReceivedBlock){ headersReceivedBlock(newResponseHeaders); } #endif }
3: SEL willRedirectSelector;
/* ALWAYS CALLED ON MAIN THREAD! */ - (void)requestWillRedirectToURL:(NSURL *)newURL { if ([self error] || [self mainRequest]) { return; } if (delegate && [delegate respondsToSelector:willRedirectSelector]) { [delegate performSelector:willRedirectSelector withObject:self withObject:newURL]; } if (queue && [queue respondsToSelector:@selector(request:willRedirectToURL:)]) { [queue performSelector:@selector(request:willRedirectToURL:) withObject:self withObject:newURL]; } }
SEL requestFinished
/* ALWAYS CALLED ON MAIN THREAD! */ - (void)reportFinished { if (delegate && [delegate respondsToSelector:didFinishSelector]) { [delegate performSelector:didFinishSelector withObject:self]; } if (queue && [queue respondsToSelector:@selector(requestFinished:)]) { [queue performSelector:@selector(requestFinished:) withObject:self]; } #if NS_BLOCKS_AVAILABLE if(completionBlock){ completionBlock(); } #endif }
SEL requestFailed
/* ALWAYS CALLED ON MAIN THREAD! */ - (void)reportFailure { if (delegate && [delegate respondsToSelector:didFailSelector]) { [delegate performSelector:didFailSelector withObject:self]; } if (queue && [queue respondsToSelector:@selector(requestFailed:)]) { [queue performSelector:@selector(requestFailed:) withObject:self]; } #if NS_BLOCKS_AVAILABLE if(failureBlock){ failureBlock(); } #endif }
相关推荐
瓜牛呱呱 2020-11-12
柳木木的IT 2020-11-04
yifouhu 2020-11-02
lei0 2020-11-02
源码zanqunet 2020-10-28
源码zanqunet 2020-10-26
一叶梧桐 2020-10-14
码代码的陈同学 2020-10-14
lukezhong 2020-10-14
lzzyok 2020-10-10
anchongnanzi 2020-09-21
clh0 2020-09-18
changcongying 2020-09-17
星辰大海的路上 2020-09-13
abfdada 2020-08-26
mzy000 2020-08-24
shenlanse 2020-08-18
zhujiangtaotaise 2020-08-18
xiemanR 2020-08-17