I'm developing an application and I need to write a message in Twitter (when user clicks on twitter icon).
How can I detect does Twitter application installed or not?
I'm developing an application and I need to write a message in Twitter (when user clicks on twitter icon).
How can I detect does Twitter application installed or not?
Just check using canOpenURL(_:).
Swift 3.0
if (UIApplication.shared.canOpenURL(URL(string:"twitter://"))) {
print("Twitter is installed")
}
Swift 2.3 or lower
if (UIApplication.sharedApplication().canOpenURL(NSURL(string:"twitter://"))) {
print("Twitter is installed")
}
You can try to check if the app can open an URL on that application
extension UIApplication {
class func tryURL(_ urls: [String]) {
let application = UIApplication.shared
for urlString in urls {
if let url = URL(string: urlString) {
if application.canOpenURL(url) {
//Do your stuff
}
}
}
}
}