我正在做类似的事情来下载文件。一切正常,而不是我想用来制作下载进度条的委托 didReceiveData:
NSURL *URL = [NSURL URLWithString:path];
RKRequest *downloadRequest = [RKRequest requestWithURL:URL];
downloadRequest.delegate = self;
downloadRequest.method = RKRequestMethodGET;
[downloadRequest sendSynchronously];
之后,调用以下委托:
- (void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response
{
NSLog(@"TEST didLoadResponse");
}
但委托 didReceiveData 从未被调用:
- (void)request:(RKRequest *)request didReceiveData:(NSInteger)bytesReceived totalBytesReceived:(NSInteger)totalBytesReceived totalBytesExpectedToReceive:(NSInteger)totalBytesExpectedToReceive
{
NSLog(@"TEST didReceiveData");
}
任何人的想法?我真的尝试了很多,我只是没有发现任何错误。可能它与我如何创建我的RKRequest
?
编辑:如果我改变它,它的工作原理:
NSURL *URL = [NSURL URLWithString:path];
RKClient *client = [[RKClient alloc] initWithBaseURL:URL];
RKRequest *downloadRequest = [client get:@"" delegate:self];
[downloadRequest sendSynchronously];
奇怪的?
EDIT2:使用第二种解决方案,我遇到了一些线程问题,所以我想问题是我发送和同步请求会锁定线程,所以 didReceiveData 委托不会回来?