didBecomeActiveNotification 的接收器永远不会在 macCatalyst 上被调用

Receiver for didBecomeActiveNotification never gets called on macCatalyst

我有一个为 iPhone/iPads 制作的 SwiftUI 应用程序。

现在我正在尝试将其转移到 macOS。 我正在努力解决的一个问题是这个代码块:

    .onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification)) { _ in
        print("Never called on macOS. Works fine on iPhones.")
        // Do some more stuff.
    }

A​​pple 文档说它在 Mac Catalyst 13.0+ 上可用,但在 macOS 上永远不会调用此代码。

所以我的问题是:

您将程序启动后应该执行的 macCatalyst 代码放在哪里(例如 TouchID 身份验证)?

Where do you put macCatalyst code that should be executed once the program starts (TouchID authentication, e.g.)?

SceneDelegate

    func sceneDidBecomeActive(_ scene: UIScene) {
        print(#function);
        // Called when the scene has moved from an inactive state to an active state.
        // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
    }

一旦应用程序在 macCatalyst 中启动,它就会被调用。