Skip to content
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

[Bug] iOS API call made using HttpClient call gets cancelled when we swipe to open Control center #9199

Closed
muffadal53 opened this issue Jul 27, 2020 · 1 comment

Comments

@muffadal53
Copy link

Ok, I did some research, and if you are using HttpClient directly, and not NSUrlSessionHandler this is expected behavior.

My fellow engineer wrote it up in great detail here but in short:

"Once your application leaves the forground, we have to kill outstanding network requests because the threadpool that runs them could be stopped at iOS's whims and that would cause your application to freeze.

You can catch this in a try catch and re-try later.

However, we have a candidate improvement/fix for this, which is described in detail here:

#7080 (comment)

Hi @chamons,

So if I understand correctly you mean that If I use "NSUrlSessionHandler" in my Xamarin forms application (only for iOS) then the HttpClient API call won't get cancelled when the application leaves foreground? And if yes then which one from two approaches should I choose from below.

  • Approach 1:

// create a background configuration for the application var configuration = NSUrlSessionConfiguration.CreateBackgroundSessionConfiguration ("my.app.identifier"); // set any specific requirements in the configuration, in this case, we are downloading a lot of data, do always use wifi configuration.AllowsCellularAccess = true; // create the client using the configuration var client = new HttpClient (new NSUrlSessionHandler (configuration));

  • Approach 2:

var handler = new NSUrlSessionHandler () { BypassBackgroundSessionCheck = true }; var client = new HttpClient (handler);

Will await your reply.

Thanks.

Originally posted by @muffadal53 in #9176 (comment)

@chamons
Copy link
Contributor

chamons commented Jul 27, 2020

Replied in #9176 (comment)

@chamons chamons closed this as completed Jul 27, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Apr 30, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants