开发者

Store information on iphone device

开发者 https://www.devze.com 2022-12-28 12:57 出处:网络
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 textfie

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 witho开发者_C百科ut database? otherwise how to do that?


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]);
    }
} 


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 :)


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号