OSX Swift open URL in default browser

前端 未结 8 1151
情话喂你
情话喂你 2020-12-04 14:10

How to open a url in system default browser by using Swift as programming language and OSX as plattform.

I found a lot with UIApplication like

UIAppl         


        
相关标签:
8条回答
  • 2020-12-04 15:02

    Swift 3 or later

    import Cocoa
    
    let url = URL(string: "https://www.google.com")!
    if NSWorkspace.shared.open(url) {
        print("default browser was successfully opened")
    
    }
    
    0 讨论(0)
  • 2020-12-04 15:02

    macOS:

    NSWorkspace.sharedWorkspace().openURL(NSURL(string: "https://google.com")!)
    

    iOS:

    UIApplication.sharedApplication().openURL(NSURL(string: "https://google.com")!)
    
    0 讨论(0)
提交回复
热议问题