How do I decide which window to open Notification Settings in on iOS 13 for userNotificationCenter:openSettingsFor:?

521 views Asked by At

iOS has the following method that gets called so you can offer custom notification settings to a user through Notification Center or the Settings app:

func userNotificationCenter(_ center: UNUserNotificationCenter, openSettingsFor notification: UNNotification?) {
    // Open up a Settings view controller within your app or something        
}

In it you would open up some in-app settings view controller.

On iOS 12 this was easy, find the active window, find the rootViewController and toss the settings screen on top of it.

On iOS 13 you (can) have multiple windows, so I'm assuming this method could get called on any of them?

Say you have 5 windows of your app open in the background, then you open the Settings app and request your app's notification settings. Which window does it use? How would I know which window/view controller to add the settings screen on to? I wouldn't want to choose one at random and accidentally add it to one in the background and not the one that was opened.

UNNotificationResponse on the other hand does have a targetScene method so if your app is opened from a notification you can know which window to use, but this method seemingly lacks it.

Should I just iterate over the all the window scenes available to the app and find one in the foreground?

0

There are 0 answers