by Rajanandepu

Xamarin Tips: Check if notification permission got granted for iOS in Xamarin.Forms

Tuğçe

--

We can use DependencyService to check if notifications is enabled for the app.

In iOS:

[assembly: Dependency(typeof(DeviceService))]
class DeviceService : IDeviceService
{
public bool GetApplicationNotificationSettings()
{
var settings = UIApplication.SharedApplication.CurrentUserNotificationSettings.Types;
return settings != UIUserNotificationType.None;
}
}

In Forms:

public interface IDeviceService
{
bool GetApplicationNotificationSettings();
}

And after these, you can call your DependencyService from your page or view model like this:

bool isNotificationEnabled = DependencyService.Get<IDeviceService>().GetApplicationNotificationSettings();

--

--

No responses yet