2

我已经使用此代码在这里登录,之后我使用 Pinning 将数据保存在本地数据库中。

[PFUser logInWithUsernameInBackground:name password:pass
                                block:^(PFUser *User, NSError *error) {
                                    if (User) {
                                        // Do stuff after successful login.

                                        [User pinInBackground];//save in Local DB
                                        NSLog(@"User Logged in");

                                        //fetching Profile image from Parse
                                        PFFile *userImageFile = User[@"profilePic"];
                                        [userImageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
                                            if (!error) {
                                                UIImage *proimage = [UIImage imageWithData:imageData];
                                                self.profilepic.image=proimage;
                                            }
                                        }];
                                        //getting data from parse
                                        [_labelname setText:User.username];
                                        [_labelGender setText:User[@"gender"]];
                                        [_labelAge setText:User[@"age"]];
                                        [_labelLocation setText:User[@"location"]];

                                        [_labelPrefGender setText:User[@"prefgender"]];
                                        [_labelPrefAge1 setText:User[@"prefAge1"]];
                                        [_labelPrefAge2 setText:User[@"prefAge2"]];
                                        [_labelPrefLocation setText:User[@"prefLocation"]];

                                        } else {
                                        NSLog(@" The login failed. Check error to see why.");
                                    }
                          [User saveEventually];
                                    [self getDataFromLocal];
                                }];

之后在 getDataFromLocal 中,我尝试从本地数据库中获取数据。但不知道下一步该怎么做?帮助我,因为我是 iOS 和 Parse 的新手。

-(void)getDataFromLocal{

PFQuery *query = [PFQuery queryWithClassName:@"User"];
[query fromLocalDatastore];
[query whereKey:@"username" equalTo:@"ira"];

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {
        NSLog(@"%@", objects);
    }else{
        NSLog(@"Erro: %@", error.localizedDescription);
    }
}];

[[query findObjectsInBackground] continueWithBlock:^id(BFTask *task) {
    // Update the UI
        if (task.error) {
        // something went wrong;
        return task;
    }
        else{
    NSLog(@"task is: %@",task.result);
    // task.result will be your game score
  //  [_labelname setText:task.result];

            return task;
        }
}];

请帮帮我。为每一个有用的建议点赞。

4

0 回答 0