Search code examples
iosswiftuikitapple-push-notificationsios15

iOS 15: Enabling "Configure in App" option for notifications


In iOS 15, the notifications center got a bit of an overhaul. It's now possible to swipe a notification to the left and choose between some "Options". All of these options relate to the notification settings for the app that presented the notification.

What I have noticed is that some apps have an additional option that lets the user configure the in-app notification settings. I am having problems figuring out how to enable this option.

Here is an example of Snapchat which has the additional option, "Configure in Snapchat"

Screenshot of example

I've tried reading up on Apple's documentation regarding UNUserNotificationCenter without finding anything that mentions this option.

Note: This does not seem to be related to UNNotificationAction as that adds options when long-pressing the notification.


Solution

  • @dan was right!

    When requesting authorization for push from UNUserNotificationCenter, UNAuthorizationOptionProvidesAppNotificationSettings should be added as an option.

    var options: UNAuthorizationOptions = [.alert, .sound, .badge]
            
    if #available(iOS 12.0, *) {
        options.insert(.providesAppNotificationSettings)
    }
    
    UNUserNotificationCenter.current().requestAuthorization(options: options) { 
        pushAuthStatus, _ in
        DispatchQueue.main.async {
            UIApplication.shared.registerForRemoteNotifications()
            completion(pushAuthStatus)
        }
    }
    

    Then all you need to do is to add the following function in the UNUserNotificationCenterDelegate to handle what happens when a user clicks the newly added option.

    func userNotificationCenter(_: UNUserNotificationCenter, openSettingsFor _: UNNotification?) {
        // Route to settings view
    }