4

I have sample app with a button. On click button should be taking the user to push notification service for my app to be able to disable them or enable. I know how to get to the general setting with this sample code but I think for notification probably you need some additional parameters like bundleId.

My question is more about URL for push notification for my app not only get to general setup as this is shown on code sample below

Sample code:

@IBAction func pushNotificationSettings(button: UIButton) {
    guard let settingsUrl = URL(string: UIApplicationOpenSettingsURLString) else {
        return
    }

    if UIApplication.shared.canOpenURL(settingsUrl) {
        if #available(iOS 10.0, *) {
            UIApplication.shared.open(settingsUrl, completionHandler: { (success) in
                print("Settings opened: \(success)") // Prints true
            })
        } else {
            // Fallback on earlier versions
        }
    }
}
MarJano
  • 1,257
  • 2
  • 18
  • 39
  • Check this question answers https://stackoverflow.com/questions/5655674/opening-the-settings-app-from-another-app – Lucho Dec 15 '17 at 14:56
  • 2
    Possible duplicate of [Opening the Settings app from another app](https://stackoverflow.com/questions/5655674/opening-the-settings-app-from-another-app) – Bilal Dec 15 '17 at 15:37
  • 1
    All answer only talking about getting into general tab but question is how to get to application push notification setting to enable/disable it – MarJano Dec 18 '17 at 07:59
  • @MarceliJanowski 'You can only open app setting page but not the notification setting page.' found in https://stackoverflow.com/q/35889412/1996294 – Ashok Dec 26 '17 at 10:20

1 Answers1

0

For IOS 10 or above

 UNUserNotificationCenter.current().getNotificationSettings { (settings) in
        if settings.authorizationStatus == .authorized {
            // Notifications are allowed
        }
        else {
            // Either denied or notDetermined

            let alertController = UIAlertController(title: nil, message: "Do you want to change notifications settings?", preferredStyle: .alert)

            let action1 = UIAlertAction(title: "Settings", style: .default) { (action:UIAlertAction) in
                if let appSettings = NSURL(string: UIApplication.openSettingsURLString) {
                    UIApplication.shared.open(appSettings as URL, options: [:], completionHandler: nil)
                }
            }

            let action2 = UIAlertAction(title: "Cancel", style: .cancel) { (action:UIAlertAction) in
            }

            alertController.addAction(action1)
            alertController.addAction(action2)
            self.present(alertController, animated: true, completion: nil)
        }
    }
stm apps
  • 51
  • 4