我试图从我的应用程序发布一些内容到Twitter,因为不幸的是,旧的方式不再适用,所以我实现了twitterKit并找到了一些峰值。
当我没有安装应用程序时,它会运行下面的完成块,这很奇怪,因为我必须手动解除警报,因为警报没有任何按钮来执行此操作。
但我真正的问题是我安装了Twitter应用程序并且我已经进行了记录。但是我无法通过推特套件检测到它。 当我按下分享到Twitter按钮时,应用程序切换到新视图,是否要求我将我的应用程序连接到我的推特(如果我没有记录,我有一个登录名和密码框,但结果是总是一样...) 当我按下" Connect"时,视图返回到我的应用程序并且没有任何反应,完成块永远不会被调用...我在iOs 11和x-code 9工作但是我&#39我试过与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)
})
}
}
}
在控制台中我收到此错误: [快照]快照至少一次渲染的视图(0x105977000,UIKeyboardImpl)需要在屏幕更新后:是。
编辑:我解决了在appDelegate中添加此方法的问题:
func application(_ app:UIApplication,open url:URL,options:[UIApplicationOpenURLOptionsKey:Any] = [:]) - >布尔{ 返回Twitter.sharedInstance()。application(app,open:url,options:options) }
答案 0 :(得分:1)
正如您所发现的那样,您需要让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的工具包,这就是我处理它的方式(这里我也用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
}