Вы можете поместить условие в метод делегата уведомлений, чтобы отображать уведомление для указанного c контроллера представления или нет.
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let navigationController: UINavigationController = self.window?.rootViewController as! UINavigationController
if (navigationController.topViewController is FirstViewController) || (navigationController.topViewController is SecondViewController) {
//Show notification for First and Second ViewController
completionHandler([.alert, .badge, .sound])
}
else {
//Do whatever when you don't want to show notification
}
}
Надеюсь, это будет полезно для вас ...