Last active
July 18, 2023 19:32
-
-
Save williamoconnorme/65e77bdf9d54aa988b3536c47ebd357d to your computer and use it in GitHub Desktop.
Open the twitter app from your own app using Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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