When a SwiftUI app is minimized and the dock icon is clicked. The app won't be deminimized and put to the front just like other apps do.
import SwiftUI
@main
struct MyApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
MainView()
}
}
}
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
// THIS IS NEVER CALLED!!!
if !flag {
for window: AnyObject in sender.windows {
window.makeKeyAndOrderFront(self)
}
}
return true
}
}
Other delegate methods like applicationDidLaunch do get called so its not a linking issue. Does anyone know how to get this to work?