Skip to content

Instantly share code, notes, and snippets.

@yunustek
Last active January 29, 2019 15:05
Show Gist options
  • Save yunustek/49b7689fd429185496238ad4f8e7bab2 to your computer and use it in GitHub Desktop.
Save yunustek/49b7689fd429185496238ad4f8e7bab2 to your computer and use it in GitHub Desktop.
Open Application with url scheme in iOS
@IBAction func faceButtonPressed(_ sender: Any) {
let accountID: String = "1235121234"
if let url = URL(string: "fb://profile/\(accountID)"), UIApplication.shared.canOpenURL(url) {
self.openUrl(url: url)
} else if let url = URL(string: "https://www.facebook.com/\(accountName)"), UIApplication.shared.canOpenURL(url) {
self.openUrl(url: url)
}
}
@IBAction func twitterButtonPressed(_ sender: Any) {
let accountName: String = "ynstek"
if let url = URL(string: "twitter://user?screen_name=\(accountName)"), UIApplication.shared.canOpenURL(url) {
self.openUrl(url: url)
} else if let url = URL(string: "https://twitter.com/\(accountName)"), UIApplication.shared.canOpenURL(url) {
self.openUrl(url: url)
}
}
@IBAction func youtubeButtonPressed(_ sender: Any) {
let accountName: String = "ynstek"
if let url = URL(string: "youtube://user/\(accountName)"), UIApplication.shared.canOpenURL(url) {
self.openUrl(url: url)
} else if let url = URL(string: "https://www.youtube.com/\(accountName)"), UIApplication.shared.canOpenURL(url) {
self.openUrl(url: url)
}
}
@IBAction func googleButtonPressed(_ sender: Any) {
let accountName: String = "+YunusTek1"
if let url = URL(string: "gplus://plus.google.com/u/0/\(accountName)"), UIApplication.shared.canOpenURL(url) {
self.openUrl(url: url)
} else if let url = URL(string: "https://plus.google.com/\(accountName)"), UIApplication.shared.canOpenURL(url) {
self.openUrl(url: url)
}
}
func openUrl(url: URL) {
if #available(iOS 10, *) {
UIApplication.shared.open(url)
} else {
UIApplication.shared.openURL(url)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment