【问题标题】:Composing tweet in Twitterkit since Xcode 9 with Swift 4 & IOS 11自 Xcode 9 以来使用 Swift 4 和 IOS 11 在 Twitterkit 中撰写推文
【发布时间】:2017-10-19 19:26:25
【问题描述】:

自从升级到 Xcode 9 和 Swift 4 后,我一直在忙于让我的应用程序重新开始工作。但我仍在努力让我的推文作曲家工作。在 Xcode 8 中,这仍然可以正常工作...

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)
                    }
                }
            }

是我现在从 Twitter 工具包网站上随意复制粘贴并调整的内容,因为我的共享功能都在一个单独的班级中。

当这段代码启动时,我的 Twitter 应用程序正在打开,并且身份验证屏幕按照我的预期打开: Authenticating

当我连接时,它会快速向我显示我的时间线,而不仅仅是回到我的应用程序。没有排版窗口...

谁有想法?

【问题讨论】:

    标签: ios11 xcode9 swift4 twitterkit


    【解决方案1】:

    在 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
    }
    

    【讨论】:

      【解决方案2】:

      我只是对两种方法感到困惑。一旦使用错误的方法,就会出现twitter登录,输入用户名和密码点击完成,再次出现登录页面。这是一个无限循环。

      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: [:])
          }
      

      不要使用第二个! 使用第一个!

      【讨论】:

        猜你喜欢
        • 2018-01-12
        • 2018-05-31
        • 1970-01-01
        • 2018-12-06
        • 2018-06-19
        • 2015-04-11
        • 2018-07-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多