Reputation: 11175
I have been trying to add a 'Follow us on Twitter' button to my app, however I have ran into a few issues.
First of all, if the user does not have Twitter installed, the code that I intended to redirect them to the website version of Twitter instead, doesn't seem to work.
Also, how can I handle situations when the users is offline? I would like to display a UIAlert to warn them that they must have a connection to use Twitter.
Here is my code:
@IBAction func followOnTwitter(sender: AnyObject) {
if UIApplication.sharedApplication().openURL(NSURL.URLWithString("twitter://user?screen_name=AffordIt_App")) {
if UIApplication.sharedApplication().openURL(NSURL.URLWithString("https://twitter.com/AffordIt_App")) {
}
}
}
Upvotes: 1
Views: 517
Reputation: 93
From what I understand you need to see if the user has Twitter installed first.
@IBAction func followOnTwitter(sender: AnyObject) {
let screenName = "Your Twitter Handle"
let appURL = NSURL(string: "twitter://user?screen_name=\(screenName)")!
let webURL = NSURL(string: "https://twitter.com/\(screenName)")!
let application = UIApplication.sharedApplication()
if application.canOpenURL(appURL) {
application.openURL(appURL)
} else {
application.openURL(webURL)
}
}
I am new to this site and apologize if I am not posting in the proper format.
Upvotes: 1