i am creating a music application in iphone where i am integrating twitter in my iphone so that a user can listen to a particular song click on the twitter tab ,log in to twitter and post his comment in to twitter.and i need that his username and password should be saved when he click on save username and password button so that he remain logged in when he is in the application.
I have done the code of saving username and password but i get an error indicating that ""FORMAT IS NOT A STRING LITERAL AND NO FORMAT ARGUMENTS""
Here is my code:
-(IBAction)SaveAll:(id)sender{
UsernameString =[[NSString alloc]initWithFormat:text1.text]; "FORMAT IS NOT A STRING LITERAL AND NO FORMAT ARGUMENTS"
[text1 setText:UsernameString];
NSUserDefaults *UsernameDefault =[NSUserDefaults standardUserDefaults];
[UsernameDefault setObject:UsernameString forKey:@"Stringkey"];
PasswordString =[[NSString alloc]initWithFormat:text2.text]; "FORMAT IS NOT A STRING LITERAL AND NO FORMAT ARGUMENTS"
[text2 setText:PasswordString];
NSUserDefaults *PasswordDefault =[NSUserDefaults standardUserDefaults];
[PasswordDefault setObject:PasswordString forKey:@"Stringkey2"];
}
Please help me in solving this problem so that when i click on the username and password button my username and password should be saved.
Use InitWithFormat if you want to create a String that is composed by several components, like a string and an integer for example then you would do something like this
NSString *myString = [NSString stringWithFormat:@"%@ costs %i"itemName, itemprice];
itemName would be an NSString Object, itemprice would be an integer.
in your case, try doing it the following way:
UsernameString =[[NSString alloc]initWithString:text1.text];
or even easier
UsernameString = text1.text;
note: I would NOT recommend to store Passwords or any other sensitive information into userdefaults a better (more safe/secure way) to store passwords is to use the devices keychain, where stored information is heavily encrypted and access happens in a safe way.
also it's easy to use:
Simple iPhone Tutorial: Password Management using the keychain by using SFHFKeychainUtils
Hope that helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.