首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >撰写推文连接应用程序或授权web不执行任何操作

撰写推文连接应用程序或授权web不执行任何操作
EN

Stack Overflow用户
提问于 2018-02-17 04:48:11
回答 1查看 290关注 0票数 0

我跟着导游来的。https://github.com/twitter/twitter-kit-ios/wiki/Compose-Tweets

在物理设备上,如果我安装了twitter应用程序,并且我触发了一个撰写推文的操作,它会打开twitter应用程序,并要求使用登录的twitter帐户进行连接。我点击连接,然后它就会把我送回应用程序。

知道这是怎么回事吗?

我的ViewController中的操作代码

代码语言:javascript
复制
@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")
        }
    }
}
EN

回答 1

Stack Overflow用户

发布于 2018-02-18 01:36:54

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

代码语言:javascript
复制
func application(_ app: UIApplication, open url: URL, options:  
[UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

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

  return true
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48834634

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档