我正在做类似的事情来下载文件。一切正常,而不是我想用来制作下载进度条的委托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:使用第二个解决方案我遇到了一些线程问题,所以我猜问题就是im发送和同步请求将锁定线程,所以didReceiveData委托不会回来?