0

我按照这里的指南进行操作。 https://github.com/twitter/twitter-kit-ios/wiki/Compose-Tweets

在物理设备上,如果我安装了 twitter 应用程序,并且我触发了撰写推文的操作,它会打开 twitter 应用程序,并要求连接已登录的 twitter 帐户。我单击连接,然后它只是将我发送回应用程序。

知道发生了什么吗?

我的 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")
        }
    }
}
4

1 回答 1

0

在您的 AppDelegate 中使用下面的代码,它应该可以使用上面的代码处理 twitter 作曲家

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

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

  return true
}
于 2018-02-17T17:36:54.250 回答