gpt4 book ai didi

ios - twitterKit 登录完成 block 永远不会执行

转载 作者:行者123 更新时间:2023-11-29 11:40:45 26 4
gpt4 key购买 nike

我正在尝试从我的应用程序向 Twitter 发布一些内容,不幸的是,由于 iOs 11,旧方法不再适用,所以我正在实现 twitterKit 并发现一些尖峰。

当我没有安装该应用程序时,它会运行下面的完成 block ,这很奇怪,因为我必须自己手动关闭警报,因为警报没有任何按钮来执行此操作。

但我真正的问题是我安装了 Twitter 应用程序并登录了。但是我无法使用 Twitter 工具包检测到它。当我按下分享到推特按钮时,应用程序切换到一个新 View ,它是否要求我将我的应用程序连接到我的推特(如果我没有登录,我有一个登录名和密码框,但结果总是相同的...)当我按下“连接”时, View 返回到我的应用程序并且没有任何反应,永远不会调用完成 block ......我在 iOs 11 和 x-code 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)

})
}
}
}

在控制台中我收到这个错误:[快照] 对至少一次未渲染的 View (0x105977000, UIKeyboardImpl) 进行快照需要 afterScreenUpdates:YES。

编辑:我在 appDelegate 中添加这个方法解决了这个问题:

func application(_ app: UIApplication, 打开 url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { 返回 Twitter.sharedInstance().application(app, open: url, options: options)

最佳答案

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

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let twtrHandled = TWTRTwitter.sharedInstance().application(app, open: url, options: options)
return twtrHandled
}

如果你有几个可以处理 URL 的工具包,这就是我处理它的方式(这里我也使用 facebook SDK 和 Branch SDK):

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
}

关于ios - twitterKit 登录完成 block 永远不会执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46699387/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com