• Check whether Push is enabled in Xamarin Forms iOS and Android

    If you have implemented Push Notifications in your Xamarin Forms iOS and Android app (maybe as explained in Setup Xamarin Forms for iOS Push Notifications or Setup Xamarin Forms Android App for Push Notifications), you might also want to know whether user has enabled Push Notifications in his system settings so you could show a warning in case it’s disabled. As this is OS specific, there is no Xamarin Forms implementation but you could create some easy interfaces to check the status. The code is based on Evan Parsons’ code for iOS and Rene Rupperts lines for Android, so thanks to both!

    New Interface in Xamarin Forms

    First, in your Xamarin Forms PCL, create a new Interface called INotificationsInterface:

    Add class to Android

    Now add a new class in your Xamarin Forms Android Application:

    Add class to iOS

    Next, add a new class in your Xamarin Forms iOS Application:

     

    Now check whether push is enabled

    Finally, call the DependencyService in your application code in Xamarin Forms:

    If anything went wrong, I set isPushEnabled to true because I don’t want to bother the user with a warning even though he maybe has push already enabled but my app was (for whatever reason) not able to find out.

    That’s it already!

Leave a comment

If you want to share your opinion, leave a comment.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">