Here is my solution :
- Create a class NotificationManager : ObservableObject
class NotificationManager : ObservableObject {
static let instance = NotificationManager()
@Published var isChanged: Bool = false
}
- Use it in AppDelegate under this function for notification :
...
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
...
NotificationManager.instance.isChanged.toggle()
}
- In the view where your TabView is, add this ObservedObject :
@ObservedObject var notificationManager = NotificationManager.instance
- In the view where your TabView is, use it in onAppear and onChange
.onAppear {
if notificationManager.isChanged {
selection = 2
}
}
.onChange(of: notificationManager.isChanged) { newValue in
selection = 2
}
N.B. solution based on @user3441734 code!
If you have a better solution I'm interested ;-)