YTKNetwork
YTKNetwork copied to clipboard
添加链接请求,如果用户是平行调用方法,那么就会导致回调代理方法不走
比如用户有下面这样的作死操作: /** 请求具有相互依赖关系的请求 */
-
(void)sendChainRequest { RegisterApi *reg = [[RegisterApi alloc] initWithUsername:@"" password:@""]; YTKChainRequest *chainReq = [[YTKChainRequest alloc] init]; [chainReq addRequest:reg callback:^(YTKChainRequest *chainRequest, YTKBaseRequest *baseRequest) { RegisterApi *result = (RegisterApi *) baseRequest; NSString *userId = [result userId]; if (userId) { GetUserInfoApi *api = [[GetUserInfoApi alloc] initWithUserId:userId]; [chainRequest addRequest:api callback:nil]; } else { GetUserInfoApi *api = [[GetUserInfoApi alloc] initWithUserId:nil]; [chainRequest addRequest:api callback:^(YTKChainRequest * _Nonnull chainRequest, YTKBaseRequest * _Nonnull baseRequest) {
}]; }
}]; chainReq.delegate = self; // 开始请求 [chainReq addRequest:reg callback:^(YTKChainRequest * _Nonnull chainRequest, YTKBaseRequest * _Nonnull baseRequest) {
}];
[chainReq start]; } 这种情况下 第二个任务和结束回调的代理都不走 我的解决方法就是
-
(void)requestFinished:(YTKBaseRequest *)request { NSUInteger currentRequestIndex = _nextRequestIndex - 1; YTKChainCallback callback = _requestCallbackArray[currentRequestIndex]; if (callback) { callback(self, request); } if (![self startNextRequest]) { [self toggleAccessoriesWillStopCallBack]; if ([_delegate respondsToSelector:@selector(chainRequestFinished:)]) { [_delegate chainRequestFinished:self]; [[YTKChainRequestAgent sharedAgent] removeChainRequest:self]; } [self toggleAccessoriesDidStopCallBack]; } else { // 判断else 情况 // 这个位置是不是应该做点什么 } }
框架开发者不妨试试 我解决方法不一定对 但是我测试是ok的