OHHTTPStubs: Delegate methods for NSURLSessionTaskDelegate not getting called?
Should they be getting called ?
I would like to be able to get the ‘upload progress’ of an image, but not sure if OHHTTPStubs
can do that.
This is what I’m trying to do, it’s crazy that none of the delegate methods are getting called though, we should at least hit the completion handler.
// Upload Image
- (void)uploadImage:(UIImage *)image
completionBlock:(operationCompletionBlock)completionBlock
progressBlock:(operationProgressBlock)progressBlock
{
NSData *imageData = UIImageJPEGRepresentation(image, 0.80);
NSURLRequest *request = [NSURLRequest requestWithURLString:@"/image_upload"];
NSURLSessionUploadTask *uploadTask = [_session uploadTaskWithRequest:request
fromData:imageData
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (completionBlock) {
NSError *err;
NSDictionary *d = [NSJSONSerialization JSONObjectWithData:data options:0 error:&err];
completionBlock([HIImageData imageDataFromJSONRepresentation:d], error);
}
}];
[_progressTable setObject:progressBlock forKey:uploadTask];
[uploadTask resume];
}
// From <NSURLSessionTaskDelegate> (Not Getting Called)
- (void)URLSession:(NSURLSession *)session
task:(NSURLSessionTask *)task
didSendBodyData:(int64_t)bytesSent
totalBytesSent:(int64_t)totalBytesSent totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend
{
operationProgressBlock completionBlock = [_progressTable objectForKey:task];
if (completionBlock) {
completionBlock(totalBytesSent/totalBytesExpectedToSend);
}
}
// From <NSURLSessionTaskDelegate> (Not Getting Called)
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error
{
[_progressTable removeObjectForKey:task];
}
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Comments: 18 (17 by maintainers)
Commits related to this issue
- Added Unit Tests for when NSURLSession uses a custom delegate (NSURLSessionDataDelegate) All fine here (cc #40) — committed to AliSoftware/OHHTTPStubs by AliSoftware 11 years ago
- Added "Known Limitations" to README (+ Static Analyzer now analyzes code in Unit Tests too) — committed to AliSoftware/OHHTTPStubs by AliSoftware 11 years ago
- Added Unit Tests for when NSURLSession uses a custom delegate (NSURLSessionDataDelegate) All fine here (cc #40) — committed to AliSoftware/OHHTTPStubs by AliSoftware 11 years ago
You are creating a task with a completion handler, so the delegate will not be called.