OSX Swift open URL in default browser
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”) }
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”) }
Swift 3+: func open(scheme: String) { if let url = URL(string: scheme) { if #available(iOS 10, *) { UIApplication.shared.open(url, options: [:], completionHandler: { (success) in print(“Open \(scheme): \(success)”) }) } else { let success = UIApplication.shared.openURL(url) print(“Open \(scheme): \(success)”) } } } Usage: open(scheme: “tweetbot://timeline”) Source
I am pretty sure you want: UIApplication.sharedApplication().openURL(NSURL(string: “tel://9809088798”)!) (note that in your question text, you put tel//:, not tel://). NSURL’s string init expects a well-formed URL. It will not turn a bunch of numbers into a telephone number. You sometimes see phone-number detection in UIWebView, but that’s being done at a higher level than NSURL. … Read more
This is listed as a known issue in the 10.3 release notes. https://developer.apple.com/library/content/releasenotes/General/RN-iOSSDK-10.3/ openURL When a third party application invokes openURL: on a tel://, facetime://, or facetime-audio:// URL, iOS displays a prompt and requires user confirmation before dialing. It is also listed in the Security content of the 10.3 update, so I’m assuming this a … Read more
As Kevin points out, URL Schemes are the only way to communicate between apps. So, no, it’s not possible to launch arbitrary apps. But it is possible to launch any app that registers a URL Scheme, whether it’s Apple’s, yours, or another developer’s. The docs are here: Defining a Custom URL Scheme for Your App … Read more