撰写推文连接应用或授权网络没有做任何事情

时间:2018-02-16 20:48:11

标签: ios swift twitterkit

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

在物理设备上,如果我安装了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")
        }
    }
}

1 个答案:

答案 0 :(得分:0)

在AppDelegate中使用以下代码,它应该可以使用上面的代码处理twitter编辑器

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

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

  return true
}