i developing an iphone app with login to mysql db by php api , after i checking the authentication of username and password that will redirect to the home screen.
The problem that i need to pass the user id to the home screen to fetch over API an other data with the logged in user, So how can i do that .. if anybody has an experience in that issue please help..
this code about the login process after checking the validity of user over PHP API:
if([serverOutput isEqualToString:@"OK"] ){
Home *home = [[[Home alloc] initWithNibName:@"Home" bundle:nil] autorelease];
home.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:home animated:YES];
[serverOutputLabel release];
} else {
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Invalid Login"
message:@"Username or Password Incorrect"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
serverOutputLabel.text=serverOutput;
[alertsuccess show];
[alertsuccess release];
[serverOutputLabel release];
}
You can store user id in
NSUSerDefautlsand if its a valid your keep them save inNSUserDefaultsotherwise clean them if it’s an invalid user.So next time when you want to send request to server, get User id from
NSUserDefaultsand append it to api.to get user id from defaults.
Also clear the defaults when user log out and on authentication failure.
also see this