Ios twitterKit登录完成块从未执行

Ios twitterKit登录完成块从未执行,ios,swift3,xcode9,twitterkit,Ios,Swift3,Xcode9,Twitterkit,我正在尝试从我的应用程序向twitter发布一些内容,不幸的是,由于iOs 11无法再使用旧的方式,因此我正在实施twitterKit,并发现一些峰值 当我没有安装应用程序时,它会运行下面的完成块,这很奇怪,因为我不得不自己手动解除警报,因为警报没有任何按钮来执行 但我真正的问题是,我安装了twitter应用程序,并且登录了。但我无法用twitter工具包检测到它。 当我按下share to twitter按钮时,应用程序切换到一个新视图,如果它要求我将我的应用程序连接到我的twitter(如果

我正在尝试从我的应用程序向twitter发布一些内容,不幸的是,由于iOs 11无法再使用旧的方式,因此我正在实施twitterKit,并发现一些峰值

当我没有安装应用程序时,它会运行下面的完成块,这很奇怪,因为我不得不自己手动解除警报,因为警报没有任何按钮来执行

但我真正的问题是,我安装了twitter应用程序,并且登录了。但我无法用twitter工具包检测到它。 当我按下share to twitter按钮时,应用程序切换到一个新视图,如果它要求我将我的应用程序连接到我的twitter(如果我没有登录,我有一个登录和密码框,但结果总是一样的…) 当我按“连接”时,视图返回到我的应用程序,但什么也没有发生,完成块永远不会调用。。。我在iOs 11和x代码9中工作,但我在iOs 10中尝试了相同的方法,得到了相同的结果。从未检测到Twitter登录。 这是我正在运行的代码,请提供任何帮助:

if (Twitter.sharedInstance().sessionStore.hasLoggedInUsers()) {
    // App must have at least one logged-in user to compose a Tweet
    let composer = TWTRComposerViewController.emptyComposer()
    present(composer, animated: false, completion: {
        print("This code never runs")
    })
} else {
    // Log in
    Twitter.sharedInstance().logIn { session, error in
        if session != nil {
            // Log in succeeded / Never happens
            let composer = TWTRComposerViewController.emptyComposer()
            composer.delegate = self
            self.present(composer, animated: true, completion: {
                print ("This code never runs")
            })
        } else {
            let alert = UIAlertController(title: "No Twitter Accounts Available", message: "You must log in before presenting a composer.", preferredStyle: .alert)

            //Only happens if I don't have the twitter app installed on my device
            self.present(alert, animated: false, completion: {
                print ("not loggued in")

                /*
                 manual dismission of the prompt as it don't have
                 any button
                 */
                sleep(3)
                alert.dismiss(animated: true, completion: nil)

            })
        }
    }
}
在控制台中,我收到以下错误: [Snapshotting]对至少未渲染一次的视图(0x105977000,UIKeyboardImpl)进行快照需要在屏幕更新后进行更新:是。

编辑:我通过在appDelegate中添加此方法解决了此问题:

func应用程序(uApp:UIApplication,打开url:url,选项:[uiApplicationOpenUrlOptions:Any]=[:])->Bool{ 返回Twitter.sharedInstance().application(应用程序,打开:url,选项:选项)
}

正如您所发现的,当应用程序从twitter重定向回来时,您需要让TwitterKit处理重新打开应用程序的问题:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    let twtrHandled = TWTRTwitter.sharedInstance().application(app, open: url, options: options)
    return twtrHandled
}
如果您有几个工具包可以处理URL,这就是我处理URL的方式(这里我也使用facebook SDK和Branch SDK):


当这是来自Twitter时,我们如何修改它以只调用
TWTRTwitter.sharedInstance…
?“如果这个方法是从另一个来源命中的呢?或者我们应该一直调用该行,如果需要,它会处理它?”JakeT。AFAIK返回值是一个布尔值,告诉您它是否由Twitter处理。。所以我希望
TWTRTwitter.sharedInstance()
有自己的机制来检测它是否来自twitter,我明白了,非常感谢!听起来这个方法返回NO是完全可以接受的。知道会发生什么吗?我查阅了文档,但它只是说它返回一个布尔值,表示应用程序是否处理了链接。它并没有说明什么会被提醒,或者是否会产生任何后果。我最好的猜测可能是某种特定于链接的分析跟踪,也许?比如说这是一个fb广告应用程序,但你不处理它,fb的分析会显示这一点吗?用户的应用程序在正常的主屏幕上打开,没有问题。@JakeT。我没有真正研究过这一点,但我认为最好是返回调用
TWTRTwitter.sharedInstance()
得到的返回值。。如果twitter处理了它,那么返回true是正确的。。如果有多个工具包可以处理它(例如,我也在使用branch和facebook),我会通过调用这些工具包的相应处理程序返回逻辑或返回值-如果这些工具包中的任何一个处理了
url
,再次,逻辑OR将使最终返回值
为真
——我认为如果其中一个工具包处理了它,返回值是正确的
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    let branchHandled = Branch.getInstance().application(app, open: url, options: options)
    let fbHandled = SDKApplicationDelegate.shared.application(app, open: url, options: options)
    let twtrHandled = TWTRTwitter.sharedInstance().application(app, open: url, options: options)
    return branchHandled || fbHandled || twtrHandled
}