Sivanathan
Sivanathan

Reputation: 1213

Store information on iphone device

I am new to iphone development. In my app, i am using two UITextfield for that registering user ID and password. These user ID and password should be save on iphone device after entered text in textfield by the user. is there any idea to do that without database? otherwise how to do that?

Upvotes: 1

Views: 989

Answers (3)

Swapnil
Swapnil

Reputation: 1878

You can also use SQL Lite database as local device database..

Upvotes: 0

dodecaplex
dodecaplex

Reputation: 1171

You'd rather use the Keychain to store the password and Preferences to store user login.

Search for SFHFKeychainUtils.h (Created by Buzz Andersen on 10/20/08) for a class that allows you to perform simple keychain operation (and being able to perform them on the iPhone Simulator).

To store the user login:

NSString *defaultUsername = ...;
[[NSUserDefaults standardUserDefaults] setObject:myUserName forKey:@"myServiceUserName"];

To store the password:

NSError *wsError;   
NSString *defaultUsername = ...
if (defaultUsername && [defaultUsername length] != 0) {
    [SFHFKeychainUtils storeUsername:defaultUsername andPassword:pass forServiceName:@"MyService" updateExisting:YES error:&wsError];
    if (wsError != nil) {
        NSLog(@"Could not store password into keychain. Error: %@", [wsError localizedDescription]);
    }
} 

Upvotes: 2

balexandre
balexandre

Reputation: 75073

Have a look at the

iPhone Core Data

you will have to go deep but this is the main used layer for Saving Data as you, in your application future would probably like to save much more.

If you only want to save some settings, here's a quick and easy trick:

  • Add a Settings Bundle (Resources) File into your project
  • Compile & Run the project
  • in the iPhone Simulator, open Settings and you will see your application name, dive deep and you'll see that Settings file

The iPhone will do all the UI for you based on that XML file, just search on all possibilities that you can have, if you still need help, post it here :)

Upvotes: 0

Related Questions