1

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?

5

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")
}
  • thanks a lot, it works – Kirill Nov 14 '16 at 15:31
0

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
                    }
                }
            }
        }
    }

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.