Gary G
Gary G

Reputation: 31

how to open Twitterkit in SFSafariViewController or Webview

I am trying to integrate twitterKit in my swift project. When the twitter app is installed on my device, then it works fine, but if twitter app is not installed, it shows message "No twitter accounts available" as shown in the following code. If twitter app is not installed I want to open a web page in the app which will open twitter login page and post my tweet. This works fine for Facebook kit. Any help will be greatly appreciated. Thanks.

let composer = TWTRComposer()
        composer.setURL(NSURL(string: "https://www.google.com")! as URL)
        if (Twitter.sharedInstance().sessionStore.hasLoggedInUsers()) {
            composer.show(from: self, completion:{ (result) -> Void in
            })
        }
        else {
             Twitter.sharedInstance().logIn(with: self, completion:  { (session, error) in
                if session != nil {
                    composer.show(from: self, completion:{ (result) -> Void in
                    })
                }
                else {
                    let alert = UIAlertController(title: "No Twitter Accounts Available", message: "You must log in before presenting a composer.", preferredStyle: .alert)
                    self.present(alert, animated: false, completion: nil)
                }
            })
        }

Upvotes: 0

Views: 545

Answers (1)

Rahul Gupta
Rahul Gupta

Reputation: 161

Go to your app in twitter dashboard: https://apps.twitter.com/ > Go to app settings > Go to Callback URL and fill with any working url. And voila, it will load the webview if the Twitter app is not installed.

Hope it helps someone.

Upvotes: 1

Related Questions