Save the username & password after login for the first time and not to ask again
I am developing one ios app, in that I need to enter company-code and accesscode to login. After login for the first time with the access code, We cannot prefer to ask for accesscode again when we open the application. I mean I need to save the preferences.
And my code is here
- (IBAction)loginClicked:(id)sender {
@try {
if([[txtsecurecode text] isEqualToString:@""] || [[OrganizationCode text] isEqualToString:@""] ) {
[self alertStatus:@"Please enter Access code" :@"Login Failed!":0];
} else {
NSString *post =[[NSString alloc] initWithFormat:@"txtsecurecode=%@ @&password=%@",[txtsecurecode text],[OrganizationCode text]];
NSLog(@"PostData: %@",post);
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://mycompany.com/AccountService/security/ValidateAccess?accesscode=%@&companycode=%@&type=1", txtsecurecode.text, OrganizationCode.text]];
[[ NSUserDefaults standardUserDefaults] setValue:OrganizationCode forKey:@"OrganizationCode"];
[[ NSUserDefaults standardUserDefaults] setValue:txtsecurecode forKey:@"txtsecurecode"];
[[NSUserDefaults standardUserDefaults] synchronize];
txtsecurecode = [[NSUserDefaults standardUserDefaults] objectForKey:@"txtsecurecode"];
OrganizationCode = [[NSUserDefaults standardUserDefaults] objectForKey:@"OrganizationCode"];
// NSString *num = [[NSUserDefaults standardUserDefaults] stringForKey:@"txtsecurecode"];
NSString *responseData = [[NSString alloc]initWithData:[NSData dataWithContentsOfURL:url] encoding:NSUTF8StringEncoding];
if([responseData isEqualToString:@""]){
[self alertStatus:@"Please enter valid Access Code" :@"Login Failed !" :0];
}
else
{
responseData = [responseData stringByReplacingOccurrencesOfString:@" "" " withString:@""];
responseData = [responseData stringByReplacingOccurrencesOfString:@"\" withString:@""];
NSString* encodedString = [responseData stringByReplacingPercentEscapesUsingEncoding:
NSUTF8StringEncoding];
NSLog(@"Response ==> %@" ,encodedString);
UIWebView *webView;
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0, 320, 470)];
webView.backgroundColor = [UIColor clearColor];
webView.opaque = NO;
[webView setDelegate:self];
NSString* urlTwo = [[encodedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
stringByReplacingOccurrencesOfString:@"%22" withString:@""];
NSURL *url2;
if([urlTwo hasPrefix:@"http://"]){
url2 = [NSURL URLWithString:urlTwo];
}else{
url2 = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@" , urlTwo]];
}
NSLog(@"url2:%@", url2);
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url2];
[webView loadRequest:requestObj];
[[self view] addSubview:webView];
}
}
}
@catch (NSException * e) {
NSLog(@"Exception: %@", e);
[self alertStatus:@"Login Failed." :@"Login Failed!" :0];
}
}
I had used NSUserDefaults method to save the login credentials but it is not working. Credentials are not saving, again the app is asking for credentials.
iphone objective-c cocoa-touch
add a comment |
I am developing one ios app, in that I need to enter company-code and accesscode to login. After login for the first time with the access code, We cannot prefer to ask for accesscode again when we open the application. I mean I need to save the preferences.
And my code is here
- (IBAction)loginClicked:(id)sender {
@try {
if([[txtsecurecode text] isEqualToString:@""] || [[OrganizationCode text] isEqualToString:@""] ) {
[self alertStatus:@"Please enter Access code" :@"Login Failed!":0];
} else {
NSString *post =[[NSString alloc] initWithFormat:@"txtsecurecode=%@ @&password=%@",[txtsecurecode text],[OrganizationCode text]];
NSLog(@"PostData: %@",post);
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://mycompany.com/AccountService/security/ValidateAccess?accesscode=%@&companycode=%@&type=1", txtsecurecode.text, OrganizationCode.text]];
[[ NSUserDefaults standardUserDefaults] setValue:OrganizationCode forKey:@"OrganizationCode"];
[[ NSUserDefaults standardUserDefaults] setValue:txtsecurecode forKey:@"txtsecurecode"];
[[NSUserDefaults standardUserDefaults] synchronize];
txtsecurecode = [[NSUserDefaults standardUserDefaults] objectForKey:@"txtsecurecode"];
OrganizationCode = [[NSUserDefaults standardUserDefaults] objectForKey:@"OrganizationCode"];
// NSString *num = [[NSUserDefaults standardUserDefaults] stringForKey:@"txtsecurecode"];
NSString *responseData = [[NSString alloc]initWithData:[NSData dataWithContentsOfURL:url] encoding:NSUTF8StringEncoding];
if([responseData isEqualToString:@""]){
[self alertStatus:@"Please enter valid Access Code" :@"Login Failed !" :0];
}
else
{
responseData = [responseData stringByReplacingOccurrencesOfString:@" "" " withString:@""];
responseData = [responseData stringByReplacingOccurrencesOfString:@"\" withString:@""];
NSString* encodedString = [responseData stringByReplacingPercentEscapesUsingEncoding:
NSUTF8StringEncoding];
NSLog(@"Response ==> %@" ,encodedString);
UIWebView *webView;
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0, 320, 470)];
webView.backgroundColor = [UIColor clearColor];
webView.opaque = NO;
[webView setDelegate:self];
NSString* urlTwo = [[encodedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
stringByReplacingOccurrencesOfString:@"%22" withString:@""];
NSURL *url2;
if([urlTwo hasPrefix:@"http://"]){
url2 = [NSURL URLWithString:urlTwo];
}else{
url2 = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@" , urlTwo]];
}
NSLog(@"url2:%@", url2);
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url2];
[webView loadRequest:requestObj];
[[self view] addSubview:webView];
}
}
}
@catch (NSException * e) {
NSLog(@"Exception: %@", e);
[self alertStatus:@"Login Failed." :@"Login Failed!" :0];
}
}
I had used NSUserDefaults method to save the login credentials but it is not working. Credentials are not saving, again the app is asking for credentials.
iphone objective-c cocoa-touch
2
and what is the question?
– Antonio MG
May 3 '13 at 10:58
sorry, before completing the question it is submitted unexpectedly.. @AntonioMG
– kumar Sudheer
May 3 '13 at 11:00
In my app need to enter accesscode to login. After login for the first time with the access code, We cannot prefer to ask for accesscode again.. mean I need to save the preferences. @AntonioMG
– kumar Sudheer
May 3 '13 at 11:02
then campare with defaults values when run the app .
– Balu
May 3 '13 at 11:05
but where is the code you decide to show or skip the login page. If you didn't put any control statements there, of course it will show up every time
– guenis
May 3 '13 at 11:05
add a comment |
I am developing one ios app, in that I need to enter company-code and accesscode to login. After login for the first time with the access code, We cannot prefer to ask for accesscode again when we open the application. I mean I need to save the preferences.
And my code is here
- (IBAction)loginClicked:(id)sender {
@try {
if([[txtsecurecode text] isEqualToString:@""] || [[OrganizationCode text] isEqualToString:@""] ) {
[self alertStatus:@"Please enter Access code" :@"Login Failed!":0];
} else {
NSString *post =[[NSString alloc] initWithFormat:@"txtsecurecode=%@ @&password=%@",[txtsecurecode text],[OrganizationCode text]];
NSLog(@"PostData: %@",post);
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://mycompany.com/AccountService/security/ValidateAccess?accesscode=%@&companycode=%@&type=1", txtsecurecode.text, OrganizationCode.text]];
[[ NSUserDefaults standardUserDefaults] setValue:OrganizationCode forKey:@"OrganizationCode"];
[[ NSUserDefaults standardUserDefaults] setValue:txtsecurecode forKey:@"txtsecurecode"];
[[NSUserDefaults standardUserDefaults] synchronize];
txtsecurecode = [[NSUserDefaults standardUserDefaults] objectForKey:@"txtsecurecode"];
OrganizationCode = [[NSUserDefaults standardUserDefaults] objectForKey:@"OrganizationCode"];
// NSString *num = [[NSUserDefaults standardUserDefaults] stringForKey:@"txtsecurecode"];
NSString *responseData = [[NSString alloc]initWithData:[NSData dataWithContentsOfURL:url] encoding:NSUTF8StringEncoding];
if([responseData isEqualToString:@""]){
[self alertStatus:@"Please enter valid Access Code" :@"Login Failed !" :0];
}
else
{
responseData = [responseData stringByReplacingOccurrencesOfString:@" "" " withString:@""];
responseData = [responseData stringByReplacingOccurrencesOfString:@"\" withString:@""];
NSString* encodedString = [responseData stringByReplacingPercentEscapesUsingEncoding:
NSUTF8StringEncoding];
NSLog(@"Response ==> %@" ,encodedString);
UIWebView *webView;
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0, 320, 470)];
webView.backgroundColor = [UIColor clearColor];
webView.opaque = NO;
[webView setDelegate:self];
NSString* urlTwo = [[encodedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
stringByReplacingOccurrencesOfString:@"%22" withString:@""];
NSURL *url2;
if([urlTwo hasPrefix:@"http://"]){
url2 = [NSURL URLWithString:urlTwo];
}else{
url2 = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@" , urlTwo]];
}
NSLog(@"url2:%@", url2);
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url2];
[webView loadRequest:requestObj];
[[self view] addSubview:webView];
}
}
}
@catch (NSException * e) {
NSLog(@"Exception: %@", e);
[self alertStatus:@"Login Failed." :@"Login Failed!" :0];
}
}
I had used NSUserDefaults method to save the login credentials but it is not working. Credentials are not saving, again the app is asking for credentials.
iphone objective-c cocoa-touch
I am developing one ios app, in that I need to enter company-code and accesscode to login. After login for the first time with the access code, We cannot prefer to ask for accesscode again when we open the application. I mean I need to save the preferences.
And my code is here
- (IBAction)loginClicked:(id)sender {
@try {
if([[txtsecurecode text] isEqualToString:@""] || [[OrganizationCode text] isEqualToString:@""] ) {
[self alertStatus:@"Please enter Access code" :@"Login Failed!":0];
} else {
NSString *post =[[NSString alloc] initWithFormat:@"txtsecurecode=%@ @&password=%@",[txtsecurecode text],[OrganizationCode text]];
NSLog(@"PostData: %@",post);
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://mycompany.com/AccountService/security/ValidateAccess?accesscode=%@&companycode=%@&type=1", txtsecurecode.text, OrganizationCode.text]];
[[ NSUserDefaults standardUserDefaults] setValue:OrganizationCode forKey:@"OrganizationCode"];
[[ NSUserDefaults standardUserDefaults] setValue:txtsecurecode forKey:@"txtsecurecode"];
[[NSUserDefaults standardUserDefaults] synchronize];
txtsecurecode = [[NSUserDefaults standardUserDefaults] objectForKey:@"txtsecurecode"];
OrganizationCode = [[NSUserDefaults standardUserDefaults] objectForKey:@"OrganizationCode"];
// NSString *num = [[NSUserDefaults standardUserDefaults] stringForKey:@"txtsecurecode"];
NSString *responseData = [[NSString alloc]initWithData:[NSData dataWithContentsOfURL:url] encoding:NSUTF8StringEncoding];
if([responseData isEqualToString:@""]){
[self alertStatus:@"Please enter valid Access Code" :@"Login Failed !" :0];
}
else
{
responseData = [responseData stringByReplacingOccurrencesOfString:@" "" " withString:@""];
responseData = [responseData stringByReplacingOccurrencesOfString:@"\" withString:@""];
NSString* encodedString = [responseData stringByReplacingPercentEscapesUsingEncoding:
NSUTF8StringEncoding];
NSLog(@"Response ==> %@" ,encodedString);
UIWebView *webView;
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0, 320, 470)];
webView.backgroundColor = [UIColor clearColor];
webView.opaque = NO;
[webView setDelegate:self];
NSString* urlTwo = [[encodedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
stringByReplacingOccurrencesOfString:@"%22" withString:@""];
NSURL *url2;
if([urlTwo hasPrefix:@"http://"]){
url2 = [NSURL URLWithString:urlTwo];
}else{
url2 = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@" , urlTwo]];
}
NSLog(@"url2:%@", url2);
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url2];
[webView loadRequest:requestObj];
[[self view] addSubview:webView];
}
}
}
@catch (NSException * e) {
NSLog(@"Exception: %@", e);
[self alertStatus:@"Login Failed." :@"Login Failed!" :0];
}
}
I had used NSUserDefaults method to save the login credentials but it is not working. Credentials are not saving, again the app is asking for credentials.
iphone objective-c cocoa-touch
iphone objective-c cocoa-touch
edited Nov 19 '18 at 22:53
halfer
14.5k758111
14.5k758111
asked May 3 '13 at 10:57
kumar Sudheerkumar Sudheer
3602625
3602625
2
and what is the question?
– Antonio MG
May 3 '13 at 10:58
sorry, before completing the question it is submitted unexpectedly.. @AntonioMG
– kumar Sudheer
May 3 '13 at 11:00
In my app need to enter accesscode to login. After login for the first time with the access code, We cannot prefer to ask for accesscode again.. mean I need to save the preferences. @AntonioMG
– kumar Sudheer
May 3 '13 at 11:02
then campare with defaults values when run the app .
– Balu
May 3 '13 at 11:05
but where is the code you decide to show or skip the login page. If you didn't put any control statements there, of course it will show up every time
– guenis
May 3 '13 at 11:05
add a comment |
2
and what is the question?
– Antonio MG
May 3 '13 at 10:58
sorry, before completing the question it is submitted unexpectedly.. @AntonioMG
– kumar Sudheer
May 3 '13 at 11:00
In my app need to enter accesscode to login. After login for the first time with the access code, We cannot prefer to ask for accesscode again.. mean I need to save the preferences. @AntonioMG
– kumar Sudheer
May 3 '13 at 11:02
then campare with defaults values when run the app .
– Balu
May 3 '13 at 11:05
but where is the code you decide to show or skip the login page. If you didn't put any control statements there, of course it will show up every time
– guenis
May 3 '13 at 11:05
2
2
and what is the question?
– Antonio MG
May 3 '13 at 10:58
and what is the question?
– Antonio MG
May 3 '13 at 10:58
sorry, before completing the question it is submitted unexpectedly.. @AntonioMG
– kumar Sudheer
May 3 '13 at 11:00
sorry, before completing the question it is submitted unexpectedly.. @AntonioMG
– kumar Sudheer
May 3 '13 at 11:00
In my app need to enter accesscode to login. After login for the first time with the access code, We cannot prefer to ask for accesscode again.. mean I need to save the preferences. @AntonioMG
– kumar Sudheer
May 3 '13 at 11:02
In my app need to enter accesscode to login. After login for the first time with the access code, We cannot prefer to ask for accesscode again.. mean I need to save the preferences. @AntonioMG
– kumar Sudheer
May 3 '13 at 11:02
then campare with defaults values when run the app .
– Balu
May 3 '13 at 11:05
then campare with defaults values when run the app .
– Balu
May 3 '13 at 11:05
but where is the code you decide to show or skip the login page. If you didn't put any control statements there, of course it will show up every time
– guenis
May 3 '13 at 11:05
but where is the code you decide to show or skip the login page. If you didn't put any control statements there, of course it will show up every time
– guenis
May 3 '13 at 11:05
add a comment |
3 Answers
3
active
oldest
votes
try this
when you successfull login then save it in NSUserDefaults
NSUserDefaults *status=[NSUserDefaults standardUserDefaults];
[status setObject:@"1" forKey:@"Login"];
Next time only check
NSUserDefaults *objUserDefaults = [NSUserDefaults standardUserDefaults];
NSString *strSuccess=[objUserDefaults objectForKey:@"Login"];
if ([strSuccess isEqualToString:@"1"]) {
// just push the next view.
}
else {
// open login screen
}
OR Next option, if you care about security, the keychain.
Edit
.h file
NSUserDefaults *objUserDefaults;
@property (nonatomic,retain) NSUserDefaults *objUserDefaults;
.m file
@synthesize objUserDefaults;
Where you first time login Method write this on response
objUserDefaults = [NSUserDefaults standardUserDefaults]
[objUserDefaults setObject:@"1" forKey:@"Login"];
and when you required for login check then
NSString *strSuccess=[objUserDefaults objectForKey:@"Login"];
if ([strSuccess isEqualToString:@"1"]) {
// just push the next view.
}
else {
// open login screen
}
Hi I used single view for my application,Now How can I use this method..
– kumar Sudheer
May 3 '13 at 11:42
its simple take global object of NSUserDefaults and check it, it is 1 or not
– SAMIR RATHOD
May 3 '13 at 11:43
Can you guide me with the code Samir. Its getting late for me as I need to submit to iTunes by today.
– kumar Sudheer
May 3 '13 at 11:47
see my edited answer
– SAMIR RATHOD
May 3 '13 at 11:56
I am sorry to ask you again.. I will send you the code through paste. Can you edit and send me please..
– kumar Sudheer
May 3 '13 at 12:20
|
show 7 more comments
OrganizationCode is not a string, and you are getting it as a string with this:
OrganizationCode = [[NSUserDefaults standardUserDefaults] stringForKey:@"OrganizationCode"];
You need to use objectForKey: instead, try with that:
OrganizationCode = [[NSUserDefaults standardUserDefaults] objectForKey:@"OrganizationCode"];
And another thing, OrganizationCode seems like the name of a class, not an instance of an object, are you sure you are using it in the right way?
I update the code and run the app, The get the logcat as MOBILE[15599:907] -[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '<UITextField: 0x1d0677a0; frame = (14.5 128; 287 42); text = 'text2013'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x1d068b80>; layer = <CALayer: 0x1d0678f0>>' of class 'UITextField'. Note that dictionaries and arrays in property lists must also contain only property values.
– kumar Sudheer
May 3 '13 at 11:14
Yes, OrganisationCode is an instance of an object..
– kumar Sudheer
May 3 '13 at 11:20
add a comment |
To Store: Login Button:
-(IBAction)Login:(id)sender
{
if (success) {
NSUserDefaults *status=[NSUserDefaults standardUserDefaults];
[status setObject:@"LOGGING" forKey:@"STATUS"];
// GO TO NEXT FUNCTION ??
}
}
To Get:Validation Button:
-(void)load_view
{
NSUserDefaults *status=[NSUserDefaults standardUserDefaults];
NSString *status_str=[status objectForKey:@"STATUS"];
if ([status_str isEqualToString:@"LOGGING"]) {
// GO TO NEXT SUCCESS FUNCTION
}
else
{
// GO TO Login View
}
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16357322%2fsave-the-username-password-after-login-for-the-first-time-and-not-to-ask-again%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
try this
when you successfull login then save it in NSUserDefaults
NSUserDefaults *status=[NSUserDefaults standardUserDefaults];
[status setObject:@"1" forKey:@"Login"];
Next time only check
NSUserDefaults *objUserDefaults = [NSUserDefaults standardUserDefaults];
NSString *strSuccess=[objUserDefaults objectForKey:@"Login"];
if ([strSuccess isEqualToString:@"1"]) {
// just push the next view.
}
else {
// open login screen
}
OR Next option, if you care about security, the keychain.
Edit
.h file
NSUserDefaults *objUserDefaults;
@property (nonatomic,retain) NSUserDefaults *objUserDefaults;
.m file
@synthesize objUserDefaults;
Where you first time login Method write this on response
objUserDefaults = [NSUserDefaults standardUserDefaults]
[objUserDefaults setObject:@"1" forKey:@"Login"];
and when you required for login check then
NSString *strSuccess=[objUserDefaults objectForKey:@"Login"];
if ([strSuccess isEqualToString:@"1"]) {
// just push the next view.
}
else {
// open login screen
}
Hi I used single view for my application,Now How can I use this method..
– kumar Sudheer
May 3 '13 at 11:42
its simple take global object of NSUserDefaults and check it, it is 1 or not
– SAMIR RATHOD
May 3 '13 at 11:43
Can you guide me with the code Samir. Its getting late for me as I need to submit to iTunes by today.
– kumar Sudheer
May 3 '13 at 11:47
see my edited answer
– SAMIR RATHOD
May 3 '13 at 11:56
I am sorry to ask you again.. I will send you the code through paste. Can you edit and send me please..
– kumar Sudheer
May 3 '13 at 12:20
|
show 7 more comments
try this
when you successfull login then save it in NSUserDefaults
NSUserDefaults *status=[NSUserDefaults standardUserDefaults];
[status setObject:@"1" forKey:@"Login"];
Next time only check
NSUserDefaults *objUserDefaults = [NSUserDefaults standardUserDefaults];
NSString *strSuccess=[objUserDefaults objectForKey:@"Login"];
if ([strSuccess isEqualToString:@"1"]) {
// just push the next view.
}
else {
// open login screen
}
OR Next option, if you care about security, the keychain.
Edit
.h file
NSUserDefaults *objUserDefaults;
@property (nonatomic,retain) NSUserDefaults *objUserDefaults;
.m file
@synthesize objUserDefaults;
Where you first time login Method write this on response
objUserDefaults = [NSUserDefaults standardUserDefaults]
[objUserDefaults setObject:@"1" forKey:@"Login"];
and when you required for login check then
NSString *strSuccess=[objUserDefaults objectForKey:@"Login"];
if ([strSuccess isEqualToString:@"1"]) {
// just push the next view.
}
else {
// open login screen
}
Hi I used single view for my application,Now How can I use this method..
– kumar Sudheer
May 3 '13 at 11:42
its simple take global object of NSUserDefaults and check it, it is 1 or not
– SAMIR RATHOD
May 3 '13 at 11:43
Can you guide me with the code Samir. Its getting late for me as I need to submit to iTunes by today.
– kumar Sudheer
May 3 '13 at 11:47
see my edited answer
– SAMIR RATHOD
May 3 '13 at 11:56
I am sorry to ask you again.. I will send you the code through paste. Can you edit and send me please..
– kumar Sudheer
May 3 '13 at 12:20
|
show 7 more comments
try this
when you successfull login then save it in NSUserDefaults
NSUserDefaults *status=[NSUserDefaults standardUserDefaults];
[status setObject:@"1" forKey:@"Login"];
Next time only check
NSUserDefaults *objUserDefaults = [NSUserDefaults standardUserDefaults];
NSString *strSuccess=[objUserDefaults objectForKey:@"Login"];
if ([strSuccess isEqualToString:@"1"]) {
// just push the next view.
}
else {
// open login screen
}
OR Next option, if you care about security, the keychain.
Edit
.h file
NSUserDefaults *objUserDefaults;
@property (nonatomic,retain) NSUserDefaults *objUserDefaults;
.m file
@synthesize objUserDefaults;
Where you first time login Method write this on response
objUserDefaults = [NSUserDefaults standardUserDefaults]
[objUserDefaults setObject:@"1" forKey:@"Login"];
and when you required for login check then
NSString *strSuccess=[objUserDefaults objectForKey:@"Login"];
if ([strSuccess isEqualToString:@"1"]) {
// just push the next view.
}
else {
// open login screen
}
try this
when you successfull login then save it in NSUserDefaults
NSUserDefaults *status=[NSUserDefaults standardUserDefaults];
[status setObject:@"1" forKey:@"Login"];
Next time only check
NSUserDefaults *objUserDefaults = [NSUserDefaults standardUserDefaults];
NSString *strSuccess=[objUserDefaults objectForKey:@"Login"];
if ([strSuccess isEqualToString:@"1"]) {
// just push the next view.
}
else {
// open login screen
}
OR Next option, if you care about security, the keychain.
Edit
.h file
NSUserDefaults *objUserDefaults;
@property (nonatomic,retain) NSUserDefaults *objUserDefaults;
.m file
@synthesize objUserDefaults;
Where you first time login Method write this on response
objUserDefaults = [NSUserDefaults standardUserDefaults]
[objUserDefaults setObject:@"1" forKey:@"Login"];
and when you required for login check then
NSString *strSuccess=[objUserDefaults objectForKey:@"Login"];
if ([strSuccess isEqualToString:@"1"]) {
// just push the next view.
}
else {
// open login screen
}
edited May 3 '13 at 12:13
Kasper Munck
3,70322146
3,70322146
answered May 3 '13 at 11:24
SAMIR RATHODSAMIR RATHOD
3,11311338
3,11311338
Hi I used single view for my application,Now How can I use this method..
– kumar Sudheer
May 3 '13 at 11:42
its simple take global object of NSUserDefaults and check it, it is 1 or not
– SAMIR RATHOD
May 3 '13 at 11:43
Can you guide me with the code Samir. Its getting late for me as I need to submit to iTunes by today.
– kumar Sudheer
May 3 '13 at 11:47
see my edited answer
– SAMIR RATHOD
May 3 '13 at 11:56
I am sorry to ask you again.. I will send you the code through paste. Can you edit and send me please..
– kumar Sudheer
May 3 '13 at 12:20
|
show 7 more comments
Hi I used single view for my application,Now How can I use this method..
– kumar Sudheer
May 3 '13 at 11:42
its simple take global object of NSUserDefaults and check it, it is 1 or not
– SAMIR RATHOD
May 3 '13 at 11:43
Can you guide me with the code Samir. Its getting late for me as I need to submit to iTunes by today.
– kumar Sudheer
May 3 '13 at 11:47
see my edited answer
– SAMIR RATHOD
May 3 '13 at 11:56
I am sorry to ask you again.. I will send you the code through paste. Can you edit and send me please..
– kumar Sudheer
May 3 '13 at 12:20
Hi I used single view for my application,Now How can I use this method..
– kumar Sudheer
May 3 '13 at 11:42
Hi I used single view for my application,Now How can I use this method..
– kumar Sudheer
May 3 '13 at 11:42
its simple take global object of NSUserDefaults and check it, it is 1 or not
– SAMIR RATHOD
May 3 '13 at 11:43
its simple take global object of NSUserDefaults and check it, it is 1 or not
– SAMIR RATHOD
May 3 '13 at 11:43
Can you guide me with the code Samir. Its getting late for me as I need to submit to iTunes by today.
– kumar Sudheer
May 3 '13 at 11:47
Can you guide me with the code Samir. Its getting late for me as I need to submit to iTunes by today.
– kumar Sudheer
May 3 '13 at 11:47
see my edited answer
– SAMIR RATHOD
May 3 '13 at 11:56
see my edited answer
– SAMIR RATHOD
May 3 '13 at 11:56
I am sorry to ask you again.. I will send you the code through paste. Can you edit and send me please..
– kumar Sudheer
May 3 '13 at 12:20
I am sorry to ask you again.. I will send you the code through paste. Can you edit and send me please..
– kumar Sudheer
May 3 '13 at 12:20
|
show 7 more comments
OrganizationCode is not a string, and you are getting it as a string with this:
OrganizationCode = [[NSUserDefaults standardUserDefaults] stringForKey:@"OrganizationCode"];
You need to use objectForKey: instead, try with that:
OrganizationCode = [[NSUserDefaults standardUserDefaults] objectForKey:@"OrganizationCode"];
And another thing, OrganizationCode seems like the name of a class, not an instance of an object, are you sure you are using it in the right way?
I update the code and run the app, The get the logcat as MOBILE[15599:907] -[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '<UITextField: 0x1d0677a0; frame = (14.5 128; 287 42); text = 'text2013'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x1d068b80>; layer = <CALayer: 0x1d0678f0>>' of class 'UITextField'. Note that dictionaries and arrays in property lists must also contain only property values.
– kumar Sudheer
May 3 '13 at 11:14
Yes, OrganisationCode is an instance of an object..
– kumar Sudheer
May 3 '13 at 11:20
add a comment |
OrganizationCode is not a string, and you are getting it as a string with this:
OrganizationCode = [[NSUserDefaults standardUserDefaults] stringForKey:@"OrganizationCode"];
You need to use objectForKey: instead, try with that:
OrganizationCode = [[NSUserDefaults standardUserDefaults] objectForKey:@"OrganizationCode"];
And another thing, OrganizationCode seems like the name of a class, not an instance of an object, are you sure you are using it in the right way?
I update the code and run the app, The get the logcat as MOBILE[15599:907] -[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '<UITextField: 0x1d0677a0; frame = (14.5 128; 287 42); text = 'text2013'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x1d068b80>; layer = <CALayer: 0x1d0678f0>>' of class 'UITextField'. Note that dictionaries and arrays in property lists must also contain only property values.
– kumar Sudheer
May 3 '13 at 11:14
Yes, OrganisationCode is an instance of an object..
– kumar Sudheer
May 3 '13 at 11:20
add a comment |
OrganizationCode is not a string, and you are getting it as a string with this:
OrganizationCode = [[NSUserDefaults standardUserDefaults] stringForKey:@"OrganizationCode"];
You need to use objectForKey: instead, try with that:
OrganizationCode = [[NSUserDefaults standardUserDefaults] objectForKey:@"OrganizationCode"];
And another thing, OrganizationCode seems like the name of a class, not an instance of an object, are you sure you are using it in the right way?
OrganizationCode is not a string, and you are getting it as a string with this:
OrganizationCode = [[NSUserDefaults standardUserDefaults] stringForKey:@"OrganizationCode"];
You need to use objectForKey: instead, try with that:
OrganizationCode = [[NSUserDefaults standardUserDefaults] objectForKey:@"OrganizationCode"];
And another thing, OrganizationCode seems like the name of a class, not an instance of an object, are you sure you are using it in the right way?
answered May 3 '13 at 11:06
Antonio MGAntonio MG
19.3k33459
19.3k33459
I update the code and run the app, The get the logcat as MOBILE[15599:907] -[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '<UITextField: 0x1d0677a0; frame = (14.5 128; 287 42); text = 'text2013'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x1d068b80>; layer = <CALayer: 0x1d0678f0>>' of class 'UITextField'. Note that dictionaries and arrays in property lists must also contain only property values.
– kumar Sudheer
May 3 '13 at 11:14
Yes, OrganisationCode is an instance of an object..
– kumar Sudheer
May 3 '13 at 11:20
add a comment |
I update the code and run the app, The get the logcat as MOBILE[15599:907] -[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '<UITextField: 0x1d0677a0; frame = (14.5 128; 287 42); text = 'text2013'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x1d068b80>; layer = <CALayer: 0x1d0678f0>>' of class 'UITextField'. Note that dictionaries and arrays in property lists must also contain only property values.
– kumar Sudheer
May 3 '13 at 11:14
Yes, OrganisationCode is an instance of an object..
– kumar Sudheer
May 3 '13 at 11:20
I update the code and run the app, The get the logcat as MOBILE[15599:907] -[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '<UITextField: 0x1d0677a0; frame = (14.5 128; 287 42); text = 'text2013'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x1d068b80>; layer = <CALayer: 0x1d0678f0>>' of class 'UITextField'. Note that dictionaries and arrays in property lists must also contain only property values.
– kumar Sudheer
May 3 '13 at 11:14
I update the code and run the app, The get the logcat as MOBILE[15599:907] -[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '<UITextField: 0x1d0677a0; frame = (14.5 128; 287 42); text = 'text2013'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x1d068b80>; layer = <CALayer: 0x1d0678f0>>' of class 'UITextField'. Note that dictionaries and arrays in property lists must also contain only property values.
– kumar Sudheer
May 3 '13 at 11:14
Yes, OrganisationCode is an instance of an object..
– kumar Sudheer
May 3 '13 at 11:20
Yes, OrganisationCode is an instance of an object..
– kumar Sudheer
May 3 '13 at 11:20
add a comment |
To Store: Login Button:
-(IBAction)Login:(id)sender
{
if (success) {
NSUserDefaults *status=[NSUserDefaults standardUserDefaults];
[status setObject:@"LOGGING" forKey:@"STATUS"];
// GO TO NEXT FUNCTION ??
}
}
To Get:Validation Button:
-(void)load_view
{
NSUserDefaults *status=[NSUserDefaults standardUserDefaults];
NSString *status_str=[status objectForKey:@"STATUS"];
if ([status_str isEqualToString:@"LOGGING"]) {
// GO TO NEXT SUCCESS FUNCTION
}
else
{
// GO TO Login View
}
}
add a comment |
To Store: Login Button:
-(IBAction)Login:(id)sender
{
if (success) {
NSUserDefaults *status=[NSUserDefaults standardUserDefaults];
[status setObject:@"LOGGING" forKey:@"STATUS"];
// GO TO NEXT FUNCTION ??
}
}
To Get:Validation Button:
-(void)load_view
{
NSUserDefaults *status=[NSUserDefaults standardUserDefaults];
NSString *status_str=[status objectForKey:@"STATUS"];
if ([status_str isEqualToString:@"LOGGING"]) {
// GO TO NEXT SUCCESS FUNCTION
}
else
{
// GO TO Login View
}
}
add a comment |
To Store: Login Button:
-(IBAction)Login:(id)sender
{
if (success) {
NSUserDefaults *status=[NSUserDefaults standardUserDefaults];
[status setObject:@"LOGGING" forKey:@"STATUS"];
// GO TO NEXT FUNCTION ??
}
}
To Get:Validation Button:
-(void)load_view
{
NSUserDefaults *status=[NSUserDefaults standardUserDefaults];
NSString *status_str=[status objectForKey:@"STATUS"];
if ([status_str isEqualToString:@"LOGGING"]) {
// GO TO NEXT SUCCESS FUNCTION
}
else
{
// GO TO Login View
}
}
To Store: Login Button:
-(IBAction)Login:(id)sender
{
if (success) {
NSUserDefaults *status=[NSUserDefaults standardUserDefaults];
[status setObject:@"LOGGING" forKey:@"STATUS"];
// GO TO NEXT FUNCTION ??
}
}
To Get:Validation Button:
-(void)load_view
{
NSUserDefaults *status=[NSUserDefaults standardUserDefaults];
NSString *status_str=[status objectForKey:@"STATUS"];
if ([status_str isEqualToString:@"LOGGING"]) {
// GO TO NEXT SUCCESS FUNCTION
}
else
{
// GO TO Login View
}
}
answered May 3 '13 at 11:11
user1025285
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16357322%2fsave-the-username-password-after-login-for-the-first-time-and-not-to-ask-again%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
and what is the question?
– Antonio MG
May 3 '13 at 10:58
sorry, before completing the question it is submitted unexpectedly.. @AntonioMG
– kumar Sudheer
May 3 '13 at 11:00
In my app need to enter accesscode to login. After login for the first time with the access code, We cannot prefer to ask for accesscode again.. mean I need to save the preferences. @AntonioMG
– kumar Sudheer
May 3 '13 at 11:02
then campare with defaults values when run the app .
– Balu
May 3 '13 at 11:05
but where is the code you decide to show or skip the login page. If you didn't put any control statements there, of course it will show up every time
– guenis
May 3 '13 at 11:05