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.
Have a session class that works as a singleton and can be accessed with a static method.
To do this you can add a static method
On that class .h you should add a NSString (or a class of your choice or whatever you want) and you can access it from wherever with
[Session sharedInstance].userID
You can store
userId
in theAppDelegate
.Declare a
userId
property inAppDelegate.h
with the following code:And then synthesize it in
AppDelegate.m
with the following code:You can then use
userId
from anywhere in your app. Add an import for theAppDelegate
in the class you want to useuserId
, as follows:To retrieve the
userId
use the following code:And to set the
userId
use the following code: