如何在 macOS 中找到以前最前沿的应用程序

监听 didActivateApplicationNotification 并过滤结果获取希望找到的应用程序。

NSWorkspace.shared.notificationCenter
    .publisher(for: NSWorkspace.didActivateApplicationNotification)
    .sink(receiveValue: { [weak self] note in
        guard
            let app = note.userInfo?[NSWorkspace.applicationUserInfoKey] as? NSRunningApplication,
            app.bundleIdentifier != Bundle.main.bundleIdentifier
        else { return }
        
        self?.frontMostApp = app
    })
    .store(in: &bag)

猜你喜欢

转载自blog.csdn.net/qq_36478920/article/details/126504375