繁体   English   中英

iOS Parse 禁止用户

[英]iOS Parse ban a user

我想使用 Parse 框架在我的应用程序中禁止用户,但它不起作用。

我的用户数据库中有一个列禁止用户。 我手动设置了变量(在 parse.com 上而不是在我的应用程序中)。

在此处输入图片说明

我在 AppDelegate 中检查该值:

// Check if user is connected
    let currentUser = PFUser.currentUser()

    if currentUser != nil {
        // if user is connected, check if he is ban

        let isBan = currentUser!.objectForKey("isBan") as! Bool
        print("Is user ban ? : \(isBan)")
        if isBan == true {
            PFUser.logOutInBackground()
        }

问题 ! 我将变量“isBan”设置为 TRUE 但打印输出显示变量仍然是 FALSE...我错过了什么? 谢谢

编辑:已解决

在检查布尔值 isBan 之前,我必须刷新用户:

currentUser!.fetchInBackgroundWithBlock // refresh the user asynchronously

尝试使用valueForObject

if let currentUser = PFUser.currentUser() {
    // if user is connected, check if he is ban
    let isBan = currentUser.valueForKey("isBan") as! Bool //supposed isBan allways exist in user table
    print("Is user ban ? : \(isBan)")
    if isBan {
        PFUser.logOutInBackground()
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM