0

Since the upgrade to Xcode 9 and Swift 4, I've been quite busy in getting my apps back working again. But I'm still struggling with getting my tweet composer to work. In Xcode 8 this was still working fine...

case "Twitter":

            if (Twitter.sharedInstance().sessionStore.hasLoggedInUsers()) {
                // App must have at least one logged-in user to compose a Tweet
                let composer = TWTRComposerViewController.emptyComposer()
                UIApplication.shared.keyWindow?.rootViewController?.present(composer, animated: true, completion: nil)
            } else {
                // Log in, and then check again
                Twitter.sharedInstance().logIn { session, error in
                    if session != nil { // Log in succeeded
                        let composer = TWTRComposerViewController.emptyComposer()
                        UIApplication.shared.keyWindow?.rootViewController?.present(composer, animated: true, completion: nil)
                    } else {
                        let alert = UIAlertController(title: "No Twitter Accounts Available", message: "You must log in before presenting a composer.", preferredStyle: .alert)
                        UIApplication.shared.keyWindow?.rootViewController?.present(alert, animated: false, completion: nil)
                    }
                }
            }

Is what I now litterly copy pasted from the Twitter kit website and adjusted because I have my sharing functions all in a seperate class.

When this piece of code is started, my Twitter application is being opened, and the authenticatin screen is opened as what I kind of expect: Authenticating

When I connect, it shows me quickly my timeline, and than just goes back to my app. Without composing window...

Anyone an idea?

Ron
  • 119
  • 1
  • 10

2 Answers2

0

Problem solved with adding this in the AppDelegate:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

    let handled:Bool = true

    Twitter.sharedInstance().application(app, open: url, options: options)

    return handled
}
Ron
  • 119
  • 1
  • 10
0

I am just confused by two methods. As soon as using the wrong method, twitter login appears, enter username and password and click done and login page appears again. That's a infinity loop.

open func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        return TWTRTwitter.sharedInstance().application(app, open: url, options: options)
    }

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        return TWTRTwitter.sharedInstance().application(application, open: url, options: [:])
    }

Don't use the second one! Use the first one!

Yusuf
  • 851
  • 6
  • 14