问题描述
我有一个为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中启动应用程序,它将被调用。