0

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
Zeeshan shaikh
  • 341
  • 1
  • 5
  • 24

1 Answers1

0

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?

Adrain
  • 1,946
  • 1
  • 3
  • 7
  • That's not a problem, I am already unregistering devices if user doesn't want to receive notification. Even after un-register, the application settings on phone still have notification enabled. So here the user can get confuse that settings still show notification enabled but inside application he has already unregister. So I just want to update the application settings as well. – Zeeshan shaikh Nov 03 '21 at 08:43
  • check the update – Adrain Nov 03 '21 at 09:31
  • Again this doesn't suggest on how we can disable settings through code – Zeeshan shaikh Nov 03 '21 at 14:38