Skip to content

Instantly share code, notes, and snippets.

@williamoconnorme
Last active July 18, 2023 19:32
Show Gist options
  • Save williamoconnorme/65e77bdf9d54aa988b3536c47ebd357d to your computer and use it in GitHub Desktop.
Save williamoconnorme/65e77bdf9d54aa988b3536c47ebd357d to your computer and use it in GitHub Desktop.
Open the twitter app from your own app using Swift
func openOnTwitter() {
let screenName = "jack"
let appURL = URL(string: "twitter://user?screen_name=\(screenName)")!
let webURL = URL(string: "https://twitter.com/\(screenName)")!
let application = UIApplication.shared
if application.canOpenURL(appURL) {
application.open(appURL, options: [:], completionHandler: nil)
} else {
application.open(webURL, options: [:], completionHandler: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment