Hi,
I have this problem in my app.
When I use HttpClient. GetAsync on OnStart Method of App throw "App Unexpectedly Quit" in iOS. I use the same method in other place and it works fine but in this method crash the app in iOS. In Android works fine too.
This is my code:
public async Task<Response> Get<T>(string endpoint, string prefixtToken,string Istrick, string accessToken = null)
{
try
{
var client = new HttpClient();
var autorizationToken = prefixtToken + accessToken;
if (accessToken != null || !string.IsNullOrEmpty(accessToken))
client.DefaultRequestHeaders.Add("Authorization", autorizationToken);
client.BaseAddress = new Uri(URLBASE);
var url = string.Format("{0}", endpoint);
var response = await client.GetAsync(url);
if (!response.IsSuccessStatusCode)
{
client.Dispose();
return new Response
{
IsSuccess = false,
Message = response.StatusCode.ToString(),
};
}
var result = await response.Content.ReadAsStringAsync();
var list = JsonConvert.DeserializeObject<T>(result);
client.Dispose();
return new Response
{
IsSuccess = true,
Message = "Ok",
Result = list,
};
}
catch (Exception ex)
{
return new Response
{
IsSuccess = false,
Message = ex.Message,
};
}
}
This error isn't captured by try catch.