I made an IOS Application with a login function. I use the ASIHTTPRequest for this to check if the user exists in a MySQL database. All works fine but i want to pass the userid trough other viewcontrollers or retrieve it on other parts of the app.
Can someone push me in the right direction how to do this in the best and most secure way?
This is my the way i do a POST HTTP request to a PHP script:
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"*SOME_URL*"]];
In a callback i can retrieve the users ID, but i want to store this ID in the memory of the app for further use.
Thanks.
You can store
userIdin theAppDelegate.Declare a
userIdproperty inAppDelegate.hwith the following code:And then synthesize it in
AppDelegate.mwith the following code:You can then use
userIdfrom anywhere in your app. Add an import for theAppDelegatein the class you want to useuserId, as follows:To retrieve the
userIduse the following code:And to set the
userIduse the following code: