Reputation: 283
So I'm using parse and the User class for users to sign up and login. I'm trying to use the currentUser method to determine if someone has already logged in and then 'skip' the login procedure like so.
if ([PFUser currentUser]) {
[self performSegueWithIdentifier:@"welcome" sender:self];
}
However the welcome segue also needs to send the username of the person to the next viewcontroller. When a user naturally logs in it does this.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"welcome"]){
SheffPushHomeViewController *vc = segue.destinationViewController;
vc.userID = self.username.text;
}
}
So I was wondering if it would be possible to use the currentUser method to gain the userName from parse? This is the full method I have implemented so far. Any help would be amazing!
if ([PFUser currentUser]) {
[self performSegueWithIdentifier:@"welcome" sender:self];
PFQuery *query = [PFQuery queryWithClassName:@"User"];
[query getObjectInBackgroundWithId:currentUser block:^(PFObject *currentUser, NSError *error) {
NSString *playerName = currentUser[@"username"];
}];
}
Upvotes: 0
Views: 94
Reputation: 9258
You can obtain this value from [PFUser currentUser]
directly:
NSString *playerName = [PFUser currentUser][@"username"];
Upvotes: 2