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

问题描述

我有一个为iPhone / iPad制作的SwiftUI应用。

现在我正在尝试将其传输到macOS。 我正在努力解决的一个问题是以下代码块:

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

Apple文档称其可在Mac Catalyst 13.0+上使用,但此代码从未在macOS上调用。

所以我的问题是:

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

解决方法

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

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中启动应用程序,它将被调用。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...