Reputation: 503
I followed the guides here. https://github.com/twitter/twitter-kit-ios/wiki/Compose-Tweets
On a physical device if I have twitter app installed, and I trigger an action to compose a tweet, it opens the twitter app, asks to connect with the logged in twitter account. I click connect, and then it just sends me back to the app.
Any idea what is going on?
Code for the action in my ViewController
@IBAction func twitterAction(_ sender: Any) {
if (TWTRTwitter.sharedInstance().sessionStore.hasLoggedInUsers()) {
// App must have at least one logged-in user to compose a Tweet
let composer = TWTRComposer()
tweetComposer(composer: composer)
} else {
// Log in, and then check again
TWTRTwitter.sharedInstance().logIn { session, error in
if session != nil { // Log in succeeded
let composer = TWTRComposer()
self.tweetComposer(composer: composer)
} else {
let alert = UIAlertController(title: "No Twitter Accounts Available", message: "You must log in before presenting a composer.", preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alert.addAction(defaultAction)
self.present(alert, animated: false, completion: nil)
}
}
}
}
func tweetComposer(composer: TWTRComposer){
let composer = TWTRComposer()
composer.setText("Trying to get this to work...")
composer.show(from: self.navigationController!) { (result) in
if (result == .done) {
print("Successfully composed Tweet")
} else {
print("Cancelled composing")
}
}
}
Upvotes: 0
Views: 379
Reputation: 1
Use this code below in your AppDelegate and it should work to handle the twitter composer with your code above
func application(_ app: UIApplication, open url: URL, options:
[UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
TWTRTwitter.sharedInstance().application(app, open: url, options: options)
return true
}
Upvotes: 0