4

I am making a Todo app and there supposed to be a switch button in inside of an application settings to enable/disable all local notifications.

I tried removeAllPendingNotificationRequests() method, but it deletes all notifications altogether and i want to keep them scheduled but not doing anything. Is it even possible ?

Thanks a lot

  • 2
    Once notification permissions have been granted. Y the user, the user can make changes in the settings for your app. The only thing you can do programmatically is schedule or not schedule notifications. Scheduled notifications are delivered based on the user's settings – Paulw11 Nov 05 '18 at 12:22
  • Thanks, i don't even know if it's a good idea have two places for switching on and off notifications, it seems kinda messy. I will just redirect user to the settings page. – Honza Nejedlý Nov 06 '18 at 08:33

2 Answers2

2

you cannot change notification setting from the app but you can navigate your users to setting of your app so they can change notification settings

if let aString = URL(string: UIApplicationOpenSettingsURLString) {
            UIApplication.shared.open(aString, options: [:], completionHandler: { success in
                SlideNavigationController.sharedInstance().closeMenu {

                }
            })
        }
Jaimin
  • 141
  • 10
1

As far as I understood, you need to disable the notification requests, but save them in case the user re-enables the switch. Is that right?

In this case, you could save all pending notifications as some custom data entities in database (or file, whatever), then remove them by calling removeAllPendingNotificationRequests().

If the user re-enables the switch, you would need to re-create the notification requests from your locally saved data entities.

Yevgeniy Leychenko
  • 1,287
  • 11
  • 25
  • Yes that's correct. Thanks for the idea, i will try. Though I think it would be kinda messy, because many request will no longer be valid when user enables notifications again. – Honza Nejedlý Nov 06 '18 at 08:28