Hi all,
I'm trying to detect an app launch in a multiplatform SwiftUI app (iOS 14/macOS 11) and having a heck of a time getting onReceive() handlers to catch didFinishLaunchingNotification, despite other notifications are being received as expected.
Here's a simplified version of what I'm trying:
Do you all see anything wrong with this approach? Is this a bug in SwiftUI?
Thanks in advance!
I'm trying to detect an app launch in a multiplatform SwiftUI app (iOS 14/macOS 11) and having a heck of a time getting onReceive() handlers to catch didFinishLaunchingNotification, despite other notifications are being received as expected.
Here's a simplified version of what I'm trying:
Code Block swift import SwiftUI struct ContentView: View { #if os(iOS) let didFinishLaunchingNotification = UIApplication.didFinishLaunchingNotification let didBecomeActiveNotification = UIApplication.didBecomeActiveNotification #else let didFinishLaunchingNotification = NSApplication.didFinishLaunchingNotification let didBecomeActiveNotification = NSApplication.didBecomeActiveNotification #endif var body: some View { NavigationView { SidebarView() ListView() Text("Content!") } .onReceive(NotificationCenter.default.publisher(for: didFinishLaunchingNotification)) { _ in print("didFinishLaunchingNotification fired") } .onReceive(NotificationCenter.default.publisher(for: didBecomeActiveNotification)) { _ in print("didBecomeActiveNotification fired") } } }
Do you all see anything wrong with this approach? Is this a bug in SwiftUI?
Thanks in advance!