【问题标题】:Receiver for didBecomeActiveNotification never gets called on macCatalyst在 macCatalyst 上永远不会调用 didBecomeActiveNotification 的接收器
【发布时间】:2020-09-12 08:59:26
【问题描述】:

我有一个为 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 上永远不会调用此代码。

所以我的问题是:

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

【问题讨论】:

    标签: swift xcode swiftui mac-catalyst


    【解决方案1】:

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

    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 中启动,就会调用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-28
      • 2014-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-21
      相关资源
      最近更新 更多