hello,
My app is populate from a json data Online;
As xamarin essential not give real connection status i prefer to check online.
protected override async void OnAppearing()
{
if (CheckForInternetConnection() == true)
{
isinternet.Text = "Internet ok";
// download json
}
else
{
isinternet.Text = "Internet down";
//use old json
}
// await Navigation.PushAsync(new MainPage());
}
public static bool CheckForInternetConnection()
{
try
{
using (var client = new MyWebClient(5000))
using (client.OpenRead("http://google.com/generate_204"))
return true;
// download json data
}
catch
{
return false;
//use old json
}
}
Is it good solution? any way to make it async and not freeze app? httpclient is fastest?
I choose to download jason file then can use old one if no connection.
webclient.downloadfile is only for binary no? i need to use webclient.DownloadString and create the json file i think
Thanks