默认浏览器中的OSX Swift打开URL [英] OSX Swift open URL in default browser
本文介绍了默认浏览器中的OSX Swift打开URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过使用Swift作为编程语言并使用OSX作为平台在系统默认浏览器中打开url.
How to open a url in system default browser by using Swift as programming language and OSX as plattform.
我通过UIApplication找到了很多类似的东西
I found a lot with UIApplication like
UIApplication.sharedApplication().openURL(NSURL(string: object.url))
但这只能在iOS上使用,而不能在OSX上使用
but this works just on iOS and not on OSX
还有启动服务,发现没有快速示例,并且OSX 10.10已弃用了很多
And the Launch Services, I found has no examples for swift and there is a lot deprecated for OSX 10.10
欢迎任何帮助-谢谢.
推荐答案
Swift 3或更高版本
import Cocoa
let url = URL(string: "https://www.google.com")!
if NSWorkspace.shared.open(url) {
print("default browser was successfully opened")
}
这篇关于默认浏览器中的OSX Swift打开URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文