Question

I'm re-writing a Windows Phone app to make it cross platform using the excellent MvvmCross framework.

On Windows Phone I usually test DeviceNetworkInformation.IsNetworkAvailable to ensure I have a network connection before calling a REST service.

Is there a way of doing this in a cross-platform way using MvvmCross?

Was it helpful?

Solution

There is a cross-platform plugin Cirrious.MvvmCross.Plugins.Network specifically for Network functionality and this was originally built specifically to provide Reachability

However, sadly the WindowsPhone part of this isn't yet implemented! See https://github.com/MvvmCross/MvvmCross/blob/v3.1/Plugins/Cirrious/Network/Cirrious.MvvmCross.Plugins.Network.Phone/Plugin.cs

If you need Reachability within a cross-platform app including WindowsPhone, I'd probably opt for adding this Network plugin, and then also modifying your WindowsPhone Setup to register something like:

public class MyReachability : IMvxReachability
{
    public bool IsHostReachable(string host) 
        return // something using DeviceNetworkInformation.IsNetworkAvailable
    }
}

// registered in Setup using:
protected override void InitializeLastChance() {
    base.InitializeLastChance();
    Mvx.RegisterType<IMvxReachability, MyReachability>();
}

Longer term, I'd be happy to see a decent implementation pushed back into the MvvmCross repository.

Also linking this question to: MvvmCross Reachability on Windows Phone and Network state with mvvmcross?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top