最近一直在看ASI请求数据这一块,都快蒙了都,其实我一直都是在懵懂的。
上个月,刚进公司,同事扔给了我一份代码,打开我懵掉了,完全看不懂,因为从来没用过ASI请求,
之前都是用的AFN,封装好的工具类,用起来很简单。
公司的代码一切都很好,就是请求这点儿,搞的不尽人意,可能同事也没弄过,好多请求的地方都没顾及到,
交给我的BUG,完全都是再请求结束,或者请求开始时的判断。
我问了好多朋友,同学,都说不曾用过,只是让我百度,goole 可是,没辙吖,找不到。
于是,自己摸索一天,找到了解决方案,
其实他的请求方法很简单:
- (void)setStartedBlock:(ASIBasicBlock)aStartedBlock
{
[startedBlockrelease];
startedBlock = [aStartedBlock copy];
}
- (void)setHeadersReceivedBlock:(ASIHeadersBlock)aReceivedBlock
{
[headersReceivedBlockrelease];
headersReceivedBlock = [aReceivedBlock copy];
}
- (void)setCompletionBlock:(ASIBasicBlock)aCompletionBlock
{
[completionBlockrelease];
completionBlock = [aCompletionBlock copy];
}
- (void)setFailedBlock:(ASIBasicBlock)aFailedBlock
{
[failureBlockrelease];
failureBlock = [aFailedBlock copy];
}
- (void)setBytesReceivedBlock:(ASIProgressBlock)aBytesReceivedBlock
{
[bytesReceivedBlockrelease];
bytesReceivedBlock = [aBytesReceivedBlock copy];
}
- (void)setBytesSentBlock:(ASIProgressBlock)aBytesSentBlock
{
[bytesSentBlockrelease];
bytesSentBlock = [aBytesSentBlock copy];
}
- (void)setDownloadSizeIncrementedBlock:(ASISizeBlock)aDownloadSizeIncrementedBlock{
[downloadSizeIncrementedBlockrelease];
downloadSizeIncrementedBlock = [aDownloadSizeIncrementedBlock copy];
}
- (void)setUploadSizeIncrementedBlock:(ASISizeBlock)anUploadSizeIncrementedBlock
{
[uploadSizeIncrementedBlockrelease];
uploadSizeIncrementedBlock = [anUploadSizeIncrementedBlock copy];
}
- (void)setDataReceivedBlock:(ASIDataBlock)aReceivedBlock
{
[dataReceivedBlockrelease];
dataReceivedBlock = [aReceivedBlock copy];
}
- (void)setAuthenticationNeededBlock:(ASIBasicBlock)anAuthenticationBlock
{
[authenticationNeededBlockrelease];
authenticationNeededBlock = [anAuthenticationBlock copy];
}
- (void)setProxyAuthenticationNeededBlock:(ASIBasicBlock)aProxyAuthenticationBlock
{
[proxyAuthenticationNeededBlockrelease];
proxyAuthenticationNeededBlock = [aProxyAuthenticationBlock copy];
}
- (void)setRequestRedirectedBlock:(ASIBasicBlock)aRedirectBlock
{
[requestRedirectedBlockrelease];
requestRedirectedBlock = [aRedirectBlock copy];
}
主要的就这些,我们常用的,就是:
//开始请求
- (void)setStartedBlock:(ASIBasicBlock)aStartedBlock
{
[startedBlockrelease];
startedBlock = [aStartedBlock copy];
}
//请求完成
- (void)setCompletionBlock:(ASIBasicBlock)aCompletionBlock
{
[completionBlockrelease];
completionBlock = [aCompletionBlock copy];
}
//请求失败
- (void)setFailedBlock:(ASIBasicBlock)aFailedBlock
{
[failureBlockrelease];
failureBlock = [aFailedBlock copy];
}
所以,希望可以帮到大家都ASI的了解。