I have a login view controller that uses the php/mysql/POST function to verify if a user is authorized. Once authorized, they enter the application.
My question is, once they are in the application, how do I “grab” their username and use it to append to any data that they upload to my database while they are in my app?
I am assuming I append it to my current NSMutableData string that carries the text blocks that they upload, but how would I “grab” this username to append it?
Assuming I have two view controllers, “login” and “main”, and the content is being uploaded on “main”, how do I pass the username from the “login” view to the “main” view so that I can append it when the user hits the upload button (which resides on the main view)?
EDIT: Where I want this username retrieved is in the following:
-(IBAction)uploadImage:(id)sender {
NSLog(@"uploadImage");
//and for retrieval
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *authenticatedUsersName = [defaults objectForKey:@"username"];
NSMutableString *postString = [NSMutableString stringWithString:kPostURL];
[postString appendString:[NSString stringWithFormat:@"&%@=%@", kText, textField.text]];
[postString setString:[postString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
If you’re not concerned with security of a username, why don’t you store the username in
NSUserDefaultsupon successful authentication? You can do something like this….I think this design gives you more flexibility so you can use the username across all view controllers in your app.
post re-edit
Why can’t you just format the string somewhere in this function? Whats the exact post url format?