繁体   English   中英

在Swift iO中使用Parse在LocalStorage中出错

[英]Error in LocalStorage using Parse in Swift iOs

我是使用解析的新手。 我尝试使用解析用户注册来创建用户对象,然后尝试将User对象保存到本地存储。 现在,当我尝试检索该对象时,出现以下错误:

[Error]: No results matched the query. (Code: 101, Version: 1.7.5)

我在其中注册用户的代码

var user = PFUser()
            user.username = userNameTF.text
            user.password = passwordTF.text
            user.email = self.userProfile.userEmail
            // other fields can be set just like with PFObject
            user["gender"] = self.userProfile.userGender
            user["school"] = self.userSchoolName.text
            user["userFullName"] = self.userProfile.userFullName



            user.signUpInBackgroundWithBlock {
                (succeeded: Bool, error: NSError?) -> Void in
                if let error = error {
                    let errorString = error.userInfo?["error"] as? NSString
                    var errorCode: String = error.valueForKey("code") as! String

                } else {
                    // Hooray! Let them use the app now.
                    println("Signup Successfull")
                    self.objectId = user.objectId!

                }
            }

        user.pinInBackgroundWithBlock { (success, error) -> Void in

            if(success == true){
                self.performSegueWithIdentifier("signUpToProfile", sender: self)
            }
        }

检索保存的用户对象的代码如下所示

let query = PFQuery(className: "User")
query.fromLocalDatastore()
var queryResult =  query.getObjectInBackgroundWithId("SO3LKyHtaa").continueWithBlock {
    (task: BFTask!) -> AnyObject in
    if let error = task.error {
        // Something went wrong.
        println("Error fetching from DB")
        return task;
    }
    println(task.result.count)
    // task.result will be your game score
    return task;
}

上面的代码部分,还给我上述错误。

提前致谢。

解析会自动为您锁定已登录/已登录的PFUser。 而不是这样做并固定userId而是这样做。 正常执行注册步骤。

user.signUpInBackgroundWithBlock { (succeeded: Bool, error: NSError?) -> Void in
            if let error = error {
                let errorString = error.userInfo?["error"] as? NSString
                var errorCode: String = error.valueForKey("code") as! String

            } else {
                // Hooray! Let them use the app now.
                println("Signup Successfull")
                // Don't need to store the userId
                // Do your segue or whatever after sign up here.
            }
        }

然后在用户登录/注册后检索用户:

if let user = PFUser.currentUser()
{
     // user is now the current user object.
}
else 
{
     // User has not yet signed up or logged in show sign up/login page. 
}

这是关于它的解析文档: https : //parse.com/docs/ios/api/Classes/PFUser.html#//api/name/currentUser

同样,当您要注销用户以“取消固定”用户时,只需执行以下操作:

PFUser.logOutInBackground { // Logged out now. }

暂无
暂无

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

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