gpt4 book ai didi

macOS 上的 Swift : open Chrome with a URL as parameter

转载 作者:行者123 更新时间:2023-12-05 02:07:35 24 4
gpt4 key购买 nike

我想从我的 macOS 应用程序中使用特定的 URL 打开 Chrome。

我正在尝试这样,但不幸的是它不起作用。Chrome 已打开,但没有使用给定的 URL 字符串。

let configuration = NSWorkspace.OpenConfiguration()
configuration.arguments = [url.absoluteString]
let appUrl = URL(fileURLWithPath: "/Applications/Google Chrome.app")
NSWorkspace.shared.openApplication(at: appUrl,
configuration: configuration,
completionHandler: nil)

open() 在这种情况下对我没有帮助,因为我不想打开标准浏览器。

非常感谢您的帮助!

最佳答案

我解决了。

NSWorkspace.shared.open([url],
withApplicationAt: URL(fileURLWithPath: "/Applications/Google Chrome.app"),
configuration: configuration)

成功了

关于macOS 上的 Swift : open Chrome with a URL as parameter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61617643/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com