Cache text from UITextField - iphone

Hello
I have an app with a textfield that user have to enter his email.
Is there any way to cache the emails that have been inserted to this textfield?
I want an autocomplete of the email when the user enter the email. If this is not possible I want at least the app save the last email that the user has used. How to do that?

Use this to store the email value:
[[NSUserDefaults standarduserdefaults] setValue:#"user#domain.com" forKey:#"Email"];
To Read it back use:
NSString *sEmail = [[NSUserDefaults standarduserdefaults] stringForKey:#"Email"];

You could save the data by using NSUserDefaults - save it when the user has finished entering the e-mail address, then restore it again when the view is loaded.

If you want to store large number of emails means you have to use the property list... In NSUserDefaults you have to store only the important values
Property list

Related

storing username and password in session iphone

I want to store username and password in a session , if a user login successfully then he will be directed to the welcome screen where a logout button is exist.
now if user close the application without log out the account and restart the app the he must be directed to the welcome screen skipping the login screen. and if user restart the app after logout then he must enter the username and password to come on welcome screen. help me out. i am new to iphone.
you may store the username and password in User Defaults or in Keychain (if want to keep it secure ). So on loading the app if you find username and password stored in Userdefaults , you may directly login to welcome screen and if not stored then show the login screen...
see this is the same as you want help with iphone session login
you can store whole array in the Userdefault, UserDefault is a one type of session in the iPhone...
here you can store any value or array in the UserDefaul..
In AppDelegate.h file just declare variable...
NSUserDefaults *userDefaults;
here it not compulsory to global declare this userDefault, you can direct use the userdefault where you want
after...
In AppDelegate.m Fille in applicationDidFinishLonching: Method or anywhere which you want to store username and pssword
userDefaults = [NSUserDefaults standardUserDefaults];
[userDefault setObject:yourName forKey:#"UserName"];
[userDefault setObject:yourPassword forKey:#"Password"];
[userDefault synchronize];
after that when you want get data from this UserDefaults Use Bellow Code...
NSString *userName = [[NSUserDefaults standardUserDefaults] valueForKey:#"UserName"];
NSString *password = [[NSUserDefaults standardUserDefaults] valueForKey:#"Password"];
i hope this helpful to you...
:)

To save username & password using objective c

I am having login view & after login some list is shown...so i want to save username & password so that login view does not appear once if login made with correct ID,password directly it will show the list
As others have suggested, you can use NSUserDefaults.
If you are storing the password, then I would suggest you also add a level of security to this. You could use Secure NSUserDefaults (I've not used this personally, but seen a few people reporting it being useful). You can find that here
Or you can use the KeyChain API
If you do not care about encryption, you could save these very simply with
[[NSUserDefaults standardUserDefaults] setValue:#"username" forKey:#"username"];
[[NSUserDefaults standardUserDefaults] setValue:#"secret" forKey:#"password"];
and check those during program startup with
if (![[NSUserDefaults standardUserDefaults] valueForKey:#"username"]) {
// show the login screen
}
you may use NSUserDefaults
Apple Documentation about NSUserDefaults
You can save this in the NSUserDefaults like this :
NSUserDefaults *userDefaults = [NSUserDefaults standardDefaults];
[userDefaults setBool#"YES" forlkey#"userDidLogin"];
And you test like this :
NSUserDefaults *userDefaults = [NSUserDefaults standardDefaults];
if([userDefaults boolForKey:#"userDidLogin"])
{
.... // Go to the list View
}
This is just an indication, if you would like to put it to work , you should show your code how you implement the implémentation of login interface
NSUserDefaults is just a handy way designed for customize app's preferences. In normal situation, an app will stay in it's own sandbox and therefore other apps won't be able to access it.
However it is not the best choice to do so. It's not good practice. What you really need is keychain and see here for apple's sample code for it, it's much safer in terms of security.
there are multiple ways to save user name and password..
You can save in UserDefalt as above answer.
also you can save in plist.

How can i store data into a text file and retrieve it when the application launches again in iphone application development?

At first of all i want to say that i am newer as an iPhone application developer.So please help me. Now, My problem is, I want to make a text file in my iPhone app.If I explain it then I will say that...
When user will login in my app then he/she will give username and password, Now i want to store these data in the text file and text file will store in the documentsDirectory, when this user again lunch the application then automatically he will able to excess the app without any authentication checking if he/she does not logout from the application first time.
1) 1st person --> login [username & password] --> store username and pass into text file because new user --> enjoy application -->logout.
2) 2nd person --> login [username & password] --> store in text file into text file because new user --> enjoy application --> did not logout.
3) 2nd person again ---> will not give username and password directly he/she have to use the application -->logout.
4) 1st person now ---> login [username & password] and check by saved reading text file ---> enjoy application --> logout.
5) 2nd person now ---> login [username & password] and check by saved reading text file ---> enjoy application --> logout.
Now, my question is how can i do this full process.Can i do this using NSUserDefaults standardUserDefualts or i need to make a text file for storing username & password??
Yes you can store simple bits of data like these in standardUserDefaults.
I assume that you will check user identity though.
e.g.what if user 1 logs in but does not logout and then user2 launches the app?
Personally I would only store the username if you plan for more than one person to access the app on a specific device and I would require the password each time.
set:
[[NSUserDefaults standardUserDefaults] setObject:userNameStr forKey:userName];
[[NSUserDefaults standardUserDefaults] synchronize];
get:
userNameStr = [[NSUserDefaults standardUserDefaults] objectForKey:userName];
I would think about storing username/password in the keychain. It is more secure and you won't have to worry about that information getting hacked out of the user defaults plist. If you still want to use a username and password, consider hashing it before storing it. Then if that information gets out (unlikely, but still possible) it won't mean anything to them.
You can actually view the contents of your user defaults from Organizer, the information is just stored as plain text there, so it is not recommended to use this as a way to store username and password.

Check if app has been purchased

I am a beginner; I am trying to solve this but am unable to do so.
I have created an app that displays a few options in a table. When the user taps the cell the details of selected option is shown on another page (details are stored in a plist file).
What I want to do is to set it up so that if the user has purchased the app then only the details should be visible, but if the user has not purchased it, the user should be prompted to do so.
I have created a product ID for iTunes Connect and also created a testing account to test the app.
My problem is with the code: how should i check if user has already made the purchase?
Using NSUserDefaults is the easiest solution.
After a successful purchase:
[[NSUserDefaults standardUserDefaults]
setObject:#"purchased"
forKey:#"myPaidItem"];
[[NSUserDefaults standardUserDefaults]
synchronize];
And when you need to check if the user has purchased the item:
NSString* isPurchased =
[[NSUserDefaults standardUserDefaults]
stringForKey:#"myPaidItem"];
if ([#"purchased"
compare:isPurchased]==NSOrderedSame) {
........ }
Hope that helps
you have to store this information in appContext as a bool if the transaction is OK , boo= true
and when he want to buy another time you hve to check the value of boo wich is stored in app Context

iphone Settings application persist data

In my app I'm using an NSUserDefaults object to store the username, password and server URL in the built-in Settings app. If there is no data saved, the user is presented a login interface and upon succesful login the username and password are saved. Then in my app I have a view which displays this information, but the text is missing as if the data hasn't been saved to the Settings yet. Here's the code:
...
NSUserDefaults* appSettings = [NSUserDefaults standardUserDefaults];
[appSettings setObject:username forKey:USERNAME];
[appSettings setObject:password forKey:PASSWORD];
if ( [appSettings synchronize] ) {
// display an alert with a positive message
} else {
// display an alert with a negative message
}
So, after logging in the positive message is displayed, but when I fetch the data again there is nothing there, unless I restart the app.
What do I need to do to save the data immediatly, or at least before another view controller needs to read the settings?
The NSUserDefaults object stores its data in memory, and is a global object (to your application, anyway). Thus, anything you store in there should be immediately available to anything that tries to access it afterwards. You don't need to call synchronize here. If you're not getting your data, you should check the order of your calls to make sure they're being called when you think they are.