-
Notifications
You must be signed in to change notification settings - Fork 601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delegate methods for NSURLSessionTaskDelegate not getting called? #40
Comments
What is your |
@AliSoftware Hey there, // Session property
@property (nonatomic, strong) NSURLSession *session;
- (void) setup {
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
_session = [NSURLSession sessionWithConfiguration:config];
} The
And my stub looks like: /** Mock Image upload WS response */
[OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) {
return [request.URL.path isEqualToString:@"/image_upload"];
} withStubResponse:^OHHTTPStubsResponse *(NSURLRequest *request) {
return [[OHHTTPStubsResponse responseWithFileAtPath:OHPathForFileInBundle(@"image_upload_ws_response.json", nil)
statusCode:201
headers:@{@"Content-Type":@"text/json"}] responseTime:OHHTTPStubsDownloadSpeed3G];
}].name = @"Image Upload OK"; I could even send you the project since it's still in early-stage, should the delegates be getting called? |
@AliSoftware if you want to take a look to the code, you can check it out here. The delegate methods are in You could try to run the test case located in // HIAPIRequests.m line 37
- (void)uploadImage:(UIImage *)image
completionBlock:(operationCompletionBlock)completionBlock
progressBlock:(operationProgressBlock)progressBlock The delegate methods for #pragma mark - NSURLSessionTaskDelegate
- (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);
}
}
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error
{
[_progressTable removeObjectForKey:task];
} |
I don't understand where in your code do you set the This is not related to |
You're correct. Sorry for the hassle,
|
I may be missing something here, but I added the above line in - (void)configureURLSession
{
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
_session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil];
} The delegate methods are still not being called, is this expected behavior? PS: Another strange thing is that even though my upload speed is stated to be 3G, the 'image upload' seems to be instant. |
Please try making your code work even without Please then try to reduce the scope of your test to isolate the problem by using the simplest possible code to reproduce the issue. I'm sure that you can understand I won't have time to review all your own thousand LOC of your own project, especially if it's only to discover at the end that this is still not related to my component at all 😉 So you should try and manage to create a simple Unit Test (that test unitary cases not involving a whole bunch of custom classes not relevant to the issue) that triggers the issue, and then I will consider it as a potential real issue from my component and not from your code, and have a real Unit Test case to resolve. But if you have the same issue w/o |
Sure, will wrap it and submit a test project for you to review. Cheers! |
Please don't; I won't probably have time to review a whole project. |
Ok, will do that! |
…essionDataDelegate) All fine here (cc #40)
Hi @Goles I don't know if you managed to debug your own code, but I did some tests on my own and added a Unit Test to my own This should confirm that the issue you were having with your code was not related to (Note: the test is not executed by Travis-CI yet because Travis-CI still uses Xcode4/iOS6 SDK which does not support |
Hey there! Haven't managed to debug my own code and write the test case yet! Will take a look at your test by Sunday and if I can write a non-passing test for OHHTTPStubs I'll do so! Cheers and thanks for the heads-up! Sent from my iPhone
|
Hey there, wrote a small test case that shows that the progress delegate method is not getting called for an upload task, you can check it out here. Note that the test passes but the delegate method is not called. Maybe I'm missing something? |
I understand you didn't manage to find a failing test for any other delegate methods and download task, but only for upload? That's an issue alright, but this is quite understandable: Please create a Pull Request with your Unit Test — describing in your request that you would like to Note this would mean some refactoring of the |
Actually, I'm not even sure it's possible to simulate upload, as So except if you find something in the URL Loading System Programming Guide that describes a way to do this, I'm unfortunately quite sure this can't be done with a custom I'll keep searching but maybe Apple did forget to provide a way to implement our custom upload protocol… |
(+ Static Analyzer now analyzes code in Unit Tests too)
@AliSoftware Do you think it's still worthy to refactor and update my test? I could ask around, maybe there's another way we could do this. Cheers! |
No I don't think it's still worthy to refactor your test as if you do it will fail and will never pass until we find a way to implement upload… which is probably not possible at all. So it's still worthy to ask around in case someone finds a way to do this, but until then the Unit Test won't be useful as it would test a feature that is not implemented at all… and will probably never be if we don't find a way to. Thx anyway and don't hesitate if you have any news about a way to do this feature. |
You are creating a task with a completion handler, so the delegate will not be called. |
…essionDataDelegate) All fine here (cc #40)
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.
The text was updated successfully, but these errors were encountered: