我已使用此代码登录此处,之后我使用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;
}
}];
} 求助于我。对所有有用的建议进行投票