gpt4 book ai didi

ios - PFFacebookUtils.logInInBackground 不执行 segue

转载 作者:行者123 更新时间:2023-11-28 14:55:23 25 4
gpt4 key购买 nike

嘿,下面的代码在某种程度上不适用于 segue。它返回:

警告:尝试呈现不在窗口层次结构中的 View !

代码在 IBAction 按钮中运行。然后我在没有 PFFFacebookUtils 代码的情况下执行 segue,它工作正常。从那我猜 segue 不能从 PFFFacebookUtils 调用,因为它在后台以某种方式工作。

代码:

PFFacebookUtils.logInInBackground(withReadPermissions: permissions) {
(user: PFUser?, error: Error?) -> Void in
if let user = user {
if user.isNew {
print("User signed up and logged in through Facebook!")
self.performSegue(withIdentifier: "segueSignUpWindow", sender: nil)

} else {
print("User logged in through Facebook!")
self.performSegue(withIdentifier: "segueSignUpWindow", sender: self)
} else {
print("Uh oh. The user cancelled the Facebook login.")
self.loginCancelledLabel.alpha = 1
}
}

我尝试插入额外的代码,例如:

DispatchQueue.main.async {
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "SignUp")
self.show(vc, sender: self)
print("Hello")

或者函数:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "segueSignUpWindow") {
DispatchQueue.main.async {
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "SignUp")
self.show(vc, sender: self)
print("Hello")
}
}

没有任何作用。有人有可行的解决方案吗?我的目标是在登录或继续登录后转至另一个 Storyboard。

我查看了 stackoverflow 中的大多数线程。没有找到有效的解决方案。

最佳答案

我能得到的最接近的:

使用初始化值创建触发器 var segueLogin : Bool = false

当 PFFacebookUtils 获取 segue 所需的值时,将触发器更改为 true:

PFFacebookUtils.logInInBackground(withReadPermissions: permissions) {
(user: PFUser?, error: Error?) -> Void in
if let user = user {
if user.isNew {
print("User signed up and logged in through Facebook!")
self.segueLogin = true

} else {
print("User logged in through Facebook!")
self.segueLogin = true
}
} else {
print("Uh oh. The user cancelled the Facebook login.")
self.loginCancelledLabel.alpha = 1
}
}

然后将代码添加到 viewDidAppear 类。意识到每次 PFFFacebookUtils 完成时它都会启动。因此它检查返回值是否为真并在成功的 PFFFacebookUtils session 后执行 segue:

override func viewDidAppear(_ animated: Bool) {
if segueLogin == true {
self.performSegue(withIdentifier: "segueSingup", sender: self)
}
}

关于ios - PFFacebookUtils.logInInBackground 不执行 segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49433779/

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