At some point we found all the requests in our app have timeout of 60 seconds on iOS though we set the default value for the HTTP framework we use as 3 minutes. I tried the following piece of code to figure out if it's the library who has an issue:
try
{
using (var http = new HttpClient())
{
http.Timeout = TimeSpan.FromMinutes(1.5);
await http.GetAsync("https://httpstat.us/200?sleep=70000");
}
}
catch (Exception ex)
{
}
This code fails with the timeout exception though the timeout is set as 90 sec and the request goes for 70 sec. Turns out it doesn't override the default timeout of 60 sec. The same code works well on the fresh project.
In the project file we have <MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
Xamarin's
NSUrlSessionHandler
uses the defaultNSUrlSessionConfiguration
if you are not creating your own instance of theNSUrlSessionHandler
and providing a customNSUrlSessionConfiguration
in its .ctor.The default
NSUrlSessionConfiguration
timeouts are set to 60 seconds in iOS.So in your Xamarin.iOS application project, open the AppDelegate.cs and set the default session timeout parameters within the
FinishedLaunching
override.re: https://developer.apple.com/documentation/foundation/nsurlsessionconfiguration#//apple_ref/occ/instp/NSURLSessionConfiguration/timeoutIntervalForRequest