我正在尝试从我的应用程序向 twitter 发布一些内容,并且由于 iOs 11 不幸的是旧方式不再适用,所以我正在实施 twitterKit 并发现一些峰值。
当我没有安装应用程序时,它会运行下面的完成块,这很奇怪,因为我必须自己手动关闭警报,因为警报没有任何按钮可以执行此操作。
但我真正的问题是我安装了 twitter 应用程序并且我已登录。但我无法使用 twitter 工具包检测到它。当我按下分享到推特按钮时,应用程序切换到新视图,它是否要求我将我的应用程序连接到我的推特(如果我没有登录,我有一个登录名和密码框,但结果总是同样...)当我按“连接”时,视图返回到我的应用程序并且没有任何反应,永远不会调用完成块...我正在使用 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)
})
}
}
}
在控制台中,我收到此错误: [Snapshotting] 对至少未渲染一次的视图(0x105977000,UIKeyboardImpl)进行快照需要 afterScreenUpdates:YES。
编辑:我解决了它在appDelegate中添加这个方法:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey: Any] = [:]) -> Bool { return Twitter.sharedInstance().application(app, open: url, options: options) }