ios - 如果注销,Swift/Xcode : Why would PFUser. currentuser() 不会返回 nil?

标签 ios swift xcode

我想设置一个条件 segue(在 Swift/Xcode 中,使用解析服务器框架,由 Heroku 托管),只有当当前用户没有注销时才会执行。如果用户没有注销,它会正常工作。但是,即使用户注销,segue 仍会运行。这是代码的基本设置。

我通过以下方式调用用户注销:

PFUser.logoutinbackground()

但是,转场:

If PFUser.currentuser() != nil {

//perform segue
}

仍然会执行 segue。将 PFUser.currentuser() 打印到日志不会返回 nil。如果我将条件 segue 代码重写为:

If PFUser.currentuser()?.username != nil {
//perform segue
}

这工作正常,返回 PFUse.currentuser()?.username 到日志确实返回 nil。像这样保留它有什么特别不对的地方吗(即这会导致任何问题吗?)。另外,为什么第一个版本的 segue 代码不返回 nil?这是否与我调用 PFUser.loginoutinbackground() 而不是 PFUser.logout() (后者导致应用程序因某种原因崩溃)这一事实有关?

最佳答案

PFUser.logOut(); 这会立即注销用户。当您调用 PFUser.logoutinbackground() 时,不会立即注销用户。

PFUser.logoutinbackground()
if PFUser.currentuser() != nil {

//perform segue
}

logoutinbackground() 是异步的。这就是为什么上面的代码不会做你认为它应该做的事情。我总是使用 PFUser.logOut();

更新

确保你的代码中没有这个

PFUser.enableAutomaticUser()

关于ios - 如果注销,Swift/Xcode : Why would PFUser. currentuser() 不会返回 nil?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38707419/

相关文章:

xcode - Swift/Xcode 依赖管理方法

iOS 无法删除通知观察器。 Deinit 没有被调用

ios - 当我将它们嵌入 Stack 时,标签会自动更改其大小

ios - 单击 Firebase 动态链接后 - DynamicLinks.dynamicLinks().handleUniversalLink 返回 false

ios - 使用 Decodable 解析 JSON 返回空模型

ios - 显示联系人姓名和电话号码。从地址簿中,抛出异常 NSInvalidArgumentException

xcode - Flurry 群组分析 - 如何跟踪设备 ID?

ios - 无法为 cashape 层设置图像

ios - 静态库和 XCode 4.x

ios - 在 : 以下使用 imagePickerController 委托(delegate)函数时获取模糊引用