Switch to enable/disable local notifications (swift 4)

Viewed 1840

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 Answers

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 {

                }
            })
        }

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.

Related