Question

I am encountering very strange problem.

I am saving users email and a encrypted key with [[NSUserDefaults standardUserDefaults] synchronize] for login to my webserver with my ipad app. This method successfully saves key values and perfectly working on simulator and also perfectly working if I install app to my device with USB Cord.

But If I upload my .ipa file for enterprise users and they download and install the app [[NSUserDefaults standardUserDefaults] synchronize] doesnt save email and key and returns null.

[[NSUserDefaults standardUserDefaults] setInteger:userId forKey:@"user_id"];
[[NSUserDefaults standardUserDefaults] setObject:self.email.text forKey:@"email"];
[[NSUserDefaults standardUserDefaults] setObject:post_key forKey:@"key"];

[[NSUserDefaults standardUserDefaults] synchronize];

NSString *post_email = [[NSUserDefaults standardUserDefaults] valueForKey:@"email"];
    NSString *post_key=[[NSUserDefaults standardUserDefaults] valueForKey:@"key"];

 NSLog(@"post_email %@",post_email);
 NSLog(@"post_key %@",post_key);

LOG ON Simulator and Device

post_email xxxxxx@gmail.com
post_key xxxxxxx

LOG ON ORGANIZER Device that installed .ipa file:

��May 17 13:31:19  xxxxxx[1590] <Warning>: post_email (null)
��May 17 13:31:19  xxxxxxx[1590] <Warning>: post_key (null)

Why is this happening? How can I fix this?

EDIT FOR FUTURE REFEFRENCES::::::

Even though rmaddy's answer is correct for null values exact problem was: ASIHTTPRequest begins but never ends

and the answer was: https://groups.google.com/forum/?fromgroups#!topic/asihttprequest/fw7PDcD2wKI

Was it helpful?

Solution

To get an object from NSUserDefaults you should use objectForKey:, not valueForKey:. valueForKey: is used for key-value coding (KVC).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top