MonoTouch, test if remote device is found on local

2019-08-27 08:17发布

问题:

I am using MonoTouch to develop an app which will connect to remote devices on a network. These devices have data which can be access through http queries.

If I provide a valid IP address to a controller the app works perfectly, however it hangs for a long time if the controller is not on the network. For this reason I thought it would be good to use the Reachability.cs class which can be found here:

https://github.com/xamarin/monotouch-samples/blob/master/ReachabilitySample/reachability.cs

Instead of using google.com as the host, I am using the IP address of the controller. I have read that there is a bug with this class which causes it to not like having "http" at the beginning of the URL. Having now tried numerous things to get this working I am out of ideas.

Do anyone have any suggestions? Perhaps I am reinventing the wheel here.

回答1:

Having now tried numerous things to get this working I am out of ideas.

From your question it's not clear what issue you're having with the Reachability class. Maybe you could edit it and add more details ? e.g. what you tried so far, how it reacts like: never works, throws/crash, inconsistent results ...

Do anyone have any suggestions?

If your main issue is blocking the UI of your application then you could (and should anyway) do your connection and data transfer asynchronously (or a separate thread) and once completed update your UI (from the main thread).

E.g. using WebClient.DownloadDataAsync