项目中点击按钮开始请求,由于网络问题导致创建了多个请求解决方案。
如有相同问题继承该类就可以了。
.h文件
@interfaceBaseRequest :YTKRequest
///当前唯一在请求
@property (nonatomic, assign ,readonly) BOOL currentOnlyRequest;
///如果有相同的请求回调
@property(nonatomic,copy)void(^haveSameRequest)(YTKRequest*request);
@end
.m文件
@implementation BaseRequest
-(void)start
{
if (!self.currentOnlyRequest) {
[super start];
}else {
NSDictionary *requestsRecord = [[YTKNetworkAgent sharedAgent] valueForKeyPath:@"requestsRecord"];
for (YTKRequest *request in requestsRecord.allValues) {
if ([request isKindOfClass:[self class]]) {
if (self.haveSameRequest) {
self.haveSameRequest(self);
}
return;
}
}
[super start];
}
}
-(BOOL)currentOnlyRequest
{
return YES;
}
@end
网友评论