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
itemName would be an NSString Object, itemprice would be an integer.
in your case, try doing it the following way:
or even easier
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.