A problem has been identified where some users experience significant delays when loading or displaying content while using mobile data.
This behavior does not occur when connected to Wi-Fi, where the application works correctly. The issue has been observed in the same physical location and across different mobile carriers, while other applications do not exhibit the same problem under similar conditions.
No exceptions appear in the error logs, which suggests that the issue may be related to network latency or intermittent connectivity, not reaching the threshold to trigger a timeout within the application.
public static async Task GenerarQR(string token, string llave, string tipoQR)
{
try
{
var url = $"{Config.Active.APISIAccessQR}/{token}/{llave}/{tipoQR}";
//Se envia headers personalizados a la petición para que no se utilicen los predeterminados
var headers = new Dictionary()
{
["Accept"] = "application/json"
};
var response = await HandlingWebRequestsAsync(HttpMethod.Get, url, headers: headers);
if (response == null)
{
SendException.EnvioError(new Exception(), $"Respuesta NULA por parte del API Siaccess");
return "N/E_QR";
}
if(string.IsNullOrEmpty(response.CodigoQR))
{
SendException.EnvioError(new Exception(), $"Respuesta VACIA/NULA del valor del código de accesso por parte del API Siaccess. VALOR:{response.CodigoQR ?? "NULL"}, URL:{url}");
return "N/E_QR";
}
return response.CodigoQR;
}
catch (Exception ex)
{
SendException.EnvioError(ex, "Ocurrió un problema al generar el QR de la credencial virtual.");
throw;
}
}
public static async Task HandlingWebRequestsAsync(HttpMethod method, string uri, object body = null, Dictionary headers = null, string otherToken = "")
{
// Verifica si hay conexión a Internet antes de realizar la petición
#if ANDROID || IOS
if (!HasRealInternetAsync())
throw new HttpRequestException("No hay conexión real a Internet.");
#endif
try
{
object response = null;
await GetToken.RefreshToken();
using (var request = CreateWebRequest(method, uri, body, headers, otherToken))
{
response = await HttpClient.SendAsync(request);
}
if (typeof(HttpResponseMessage).IsAssignableFrom(typeof(T)))
{
return (T)response;
}
if (!(response as HttpResponseMessage).IsSuccessStatusCode)
{
return default;
}
//Si no se procede a devolver el contenido deserializado
//Se obtiene el contenido de la respuesta y se transforma a texto para la lectura
var content = await (response as HttpResponseMessage).Content.ReadAsStringAsync();
//Cierra completamente la conexión del HttpClient
(response as HttpResponseMessage).Dispose();
//El contenido se deserealiza para convertirlo en la clase indicada (T)
return JsonConvert.DeserializeObject(content);
}
catch (Exception ex)
{
SendException.EnvioError(ex, "Ocurrió un problema al consumir la Api" + uri + " al parecer no tiene conectividad.");
return default;
}
}
That´s my code.