Is it possible to disable Notification settings for the application in Xamarin Forms

783 views Asked by At

Is there a way to disable the alert settings from an application through code? I am already enabling these settings using below code, but I cant find any method to disable these settings again on user action.

var pushSettings = UIUserNotificationSettings.GetSettingsForTypes(
                UIUserNotificationType.Alert |
                UIUserNotificationType.Badge |
                UIUserNotificationType.Sound,
                new NSSet());

UIApplication.SharedApplication.RegisterUserNotificationSettings(pushSettings);
UIApplication.SharedApplication.RegisterForRemoteNotifications();

There is below method but it doesn't disable the notification in application settings.

 UIApplication.SharedApplication.UnregisterForRemoteNotifications
1

There are 1 answers

3
Adrain On

The problem seems to be that iOS prevents registering for push notification with Apple in a manner of time after unregistering. The Apple Docs regarding unregistering say:

You should call this method in rare circumstances only, such as when a new version of the app removes support for all types of remote notifications. Users can temporarily prevent apps from receiving remote notifications through the Notifications section of the Settings app. Apps unregistered through this method can always re-register.

https://developer.apple.com/documentation/uikit/uiapplication/1623093-unregisterforremotenotifications?preferredLanguage=occ

So, just don't call unregisterForRemoteNotifications as long as you really need to do it (see Apple Doc).

The user has total control on enabling and disabling notifications for your app, if you want to do it in code, I think you could create a popup leads to setting page. like this questions shows How to turn on and off notifications in iOS?