1

this is my problem:

I have a registration UIViewController so the user can send his information via POST.

When the user taps "send", I instantiate a NSURLSessionUploadTask using the NSURLSession uploadTaskWithRequest:fromData:completionHandler: method and, if he wants to go back, he can taps the "back" button to go back to the previous UIViewController.

When the user taps the "back" button, an UIAlertView is shown just to ask the user if he's sure to cancel or not the registration. While the UIAlertView is shown, I mark the NSURLSessionUploadTask as suspended, using the suspend method, so the user can resume the registration if he isn't sure to go back. My problem is there: when I mark the task as suspended, it seems that the NSURLSessionUploadTask ignores it and stills doing the registration showing two UIAlertViews: the one which confirms the cancelation and the one having the server response.

Please, can you help me with this? I'm doing something wrong? Maybe there's something I'm ignoring. I can't suspend and resume it later :/

Doing the upload:

uploadTask = [sesion uploadTaskWithRequest:request
                                  fromData:data
                         completionHandler:^(NSData * data, NSURLResponse * response, NSError * error)
{
    ...
}];

[uploadTask resume];

Suspending the upload in the implementation of the "back" button:

if (uploadTask != nil) && (uploadTask == NSURLSessionTaskStateRunning))
{
    [uploadTask suspend];
}

0 Answers0