iosswiftapplication-settings

Opening app's notification settings in the settings app


In the case that a user may accidentally declines to receive notifications and wants to turn notifications later, how can I use an NSURL to open the IOS Settings App to my app's notification page where they can select Allow Notifications?


Solution

  • Updated 8 Dec, 2021:

    This method will open Settings > Your App. It will show all available privacy toggles like camera, photos, notifications, cellular data, etc.

    After a comment from @Mischa below, tested and updated the answer to this (more succinct):

    if let appSettings = URL(string: UIApplication.openSettingsURLString), UIApplication.shared.canOpenURL(appSettings) {
        UIApplication.shared.open(appSettings)
    }
    

    Previous answer:

    I found the answer to this question (albeit helpful) has a bit too much assumed logic. Here is a plain and simple Swift 5 implementation if anyone else stumbles upon this question:

    if let bundleIdentifier = Bundle.main.bundleIdentifier, let appSettings = URL(string: UIApplication.openSettingsURLString + bundleIdentifier) {
        if UIApplication.shared.canOpenURL(appSettings) {
            UIApplication.shared.open(appSettings)
        }
    }