Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 932
Matt Avatar asked Mar 17 '17 03:03

Matt


People also ask

What is in app notification settings?

In-app notifications are messages that app creators can send to users within their app. They're commonly used to direct users toward points of interest to boost usage, retention, and lifetime value (LTV). Used properly, in-app notifications help users find what they're looking for and increase their satisfaction.

Where is apps and notifications in Settings on Iphone?

Go to Settings and tap Notifications. Select an app under Notification Style. Under Alerts, choose the alert style that you want. If you turn on Allow Notifications, choose when you want the notifications delivered — immediately or in the scheduled notification summary.


2 Answers

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)
    }
}
like image 197
Gligor Avatar answered Oct 11 '22 01:10

Gligor


For Swift 3, use UIApplicationOpenSettingsURLString to go to settings for your app where it shows the Notifications status and "Cellular Data"

let settingsButton = NSLocalizedString("Settings", comment: "")
let cancelButton = NSLocalizedString("Cancel", comment: "")
let message = NSLocalizedString("Your need to give a permission from notification settings.", comment: "")
let goToSettingsAlert = UIAlertController(title: "", message: message, preferredStyle: UIAlertControllerStyle.alert)

goToSettingsAlert.addAction(UIAlertAction(title: settingsButton, style: .destructive, handler: { (action: UIAlertAction) in
    DispatchQueue.main.async {
        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 {
                UIApplication.shared.openURL(settingsUrl as URL)
            } 
        }
    }
}))

logoutUserAlert.addAction(UIAlertAction(title: cancelButton, style: .cancel, handler: nil))
like image 27
CodeOverRide Avatar answered Oct 11 '22 02:10

CodeOverRide