Skip to content

Instantly share code, notes, and snippets.

@shu223
Created February 28, 2016 07:09
Show Gist options
  • Save shu223/385f0ab0dd811f90bd2a to your computer and use it in GitHub Desktop.
Save shu223/385f0ab0dd811f90bd2a to your computer and use it in GitHub Desktop.
Open one of Twitter apps with username
let username = organizer.twitter
let twitterURLs = [
"twitter://user?screen_name=\(username)", // Twitter
"tweetbot://user_profile/\(username)", // TweetBot
"echofon://user_timeline?\(username)", // Echofon
"twit://user?screen_name=\(username)", // Twittelator Pro
"x-seesmic://twitter_profile?twitter_screen_name=\(username)", // Seesmic
"x-birdfeed://user?screen_name=\(username)", // Birdfeed
"tweetings://user?screen_name=\(username)", // Tweetings
"simplytweet://?link=http://twitter.com/\(username)", // SimplyTweet
"icebird://user?screen_name=\(username)", // IceBird
"fluttr://user/\(username)", // Fluttr
]
var applicationOpened: Bool = false
let application = UIApplication.sharedApplication()
for twitterURL in twitterURLs {
if let url = NSURL(string: twitterURL) where application.canOpenURL(url) && !applicationOpened {
application.openURL(url)
applicationOpened = true
break
}
}
if !applicationOpened {
let webViewController = WebDisplayViewController()
webViewController.url = NSURL(string: "http://twitter.com/\(username)")!
webViewController.displayTitle = "@\(username)"
navigationController?.pushViewController(webViewController, animated: true)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment