[英]NSUserDefaults values are not getting saved iPhone
Using the below code to save the sessionID. 使用以下代码保存sessionID。
NSUserDefaults *sessions = [NSUserDefaults standardUserDefaults];
[sessions setObject:sID forKey:@"sessionsID"];
[sessions synchronize];
NSLog(@"Session Value Saved");
The code to retrieve the value is: 检索值的代码为:
NSUserDefaults *sessions = [NSUserDefaults standardUserDefaults];
NSString *myString = [sessions stringForKey:@"sessionsID"];
NSLog(@"nsuser: %@", myString);
But on console it is showing like: 但是在控制台上它显示为:
2012-01-03 15:37:37.292 LoginTest[574:12503] sID: c339af83caa5355d124f70e3f22c193d
2012-01-03 15:37:37.296 LoginTest[574:12503] Session Value Saved
2012-01-03 15:37:37.297 LoginTest[574:12503] Accounts: ("uid=demo@url.com", "o=Demo","o=Und")
2012-01-03 15:37:37.302 LoginTest[574:12503] sID: (null)
2012-01-03 15:37:37.304 LoginTest[574:12503] Session Value Saved
2012-01-03 15:37:37.304 LoginTest[574:12503] Accounts: (null)
2012-01-03 15:37:37.305 LoginTest[574:12503] No Session created
why is it being called two times and once it saves the values and shows them up and second time giving null. 为什么调用两次,一次将保存值并显示出来,第二次给出null。
I am using ARC. 我正在使用ARC。
I am messed-up with this... please guide me how can I resolve this issue 我对此感到困惑...请指导我如何解决此问题
We dont know why it's getting called twice; 我们不知道为什么它被调用两次; it's your app :)
这是你的应用程序:)
Put a breakpoint on [sessions setObject:sID forKey:@"sessionsID"];
在
[sessions setObject:sID forKey:@"sessionsID"];
上设置一个断点[sessions setObject:sID forKey:@"sessionsID"];
The first time this gets hit sID
will be valid. 第一次被击中的
sID
将是有效的。
Then something is happening that is invalidating sID
:( 然后发生了使
sID
无效的sID
:(
The second time it gets hit it looks like sID
is null
- you should be able to use the console / stack to work out why it's being called twice. 第二次被击中时,
sID
为null
-您应该能够使用控制台/堆栈来弄清楚为什么它被两次调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.