Is there a Xamarin Forms way of handling offline?

TobnilTobnil SEMember ✭✭
edited December 2017 in Xamarin.Forms

Hi,

I was wondering how to handle when my device goes offline.
Is there some sort of "Xamarin forms way" of doing that? Or do I have to reinvent the wheel again?

What I would be after is to detect if the device goes offline, and notify that to the user in a nice way.

Best regards,
Tobias

Best Answer

Answers

  • TobnilTobnil SEMember ✭✭

    Yeah, that was what I thought aswell. I had hoped there was a more centralized way of doing it :/
    Especially when it comes to creating the notification.. Oh well.

    Thanks for the help :)

  • JohnHardmanJohnHardman GBUniversity mod
    edited December 2017

    @Tobnil - The plugin is Xam.Plugin.Connectivity

    To monitor for changes, do:

                    CrossConnectivity.Current.ConnectivityChanged += async (sender, args) =>
                    {
                        // use args.IsConnected
                    };
    

    (caveat: I'm using an old version of the plugin. I doubt this aspect has changed, but you might want to double check)

    Also, it's worth reading the thread at https://forums.xamarin.com/discussion/comment/276460#Comment_276460

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    @Tobnil said:
    Yeah, that was what I thought aswell. I had hoped there was a more centralized way of doing it :/
    Especially when it comes to creating the notification.. Oh well.

    Thanks for the help :)

    Well... Notifications have a pretty centralized implementation. Popups are commonly done through the rg.plugins.popups nuget - but you can do a simple DisplayAlert as well.

    But if your app is going to do it, it would have to do it in keeping with theme and functionality of your app. Its not your app's responsibility to do this on behalf of the OS. After all if 10 programs did that then you'd have to dismiss 10 notices. So maybe your app just wants to put a disconnected icon on one of its buttons. Or disables all the [SEND] buttons within the app. Or puts a comment in your app's status bar.

    So how you show that in your app is going to be custom to each app.

  • TobnilTobnil SEMember ✭✭

    True indeed. Thank you very much for the answer :)

Sign In or Register to comment.