Closed irshadpc closed 9 years ago
You first need to set a secret:
[[NSUserDefaults standardUserDefaults] setSecret:@"your_secret_goes_here"]
Thanks :) nielsmouthaan
Hi Niel, I'm trying to retrieve object for key using the below code but it is crashing. NSData *data = [[NSUserDefaults standardUserDefaults] secretObjectForKey:kLoginUserData];
Please help me out what i'm doing wrong ???
Error * Assertion failure in -[NSUserDefaults secretObjectForKey:], /Users/nitishkarnekar/Documents/Anshul/RF/Backup/April/12/iOS/RetailFinance/NSUserDefaults+SecureAdditions.m:118 2016-04-12 13:35:46.394 RetailFinance[1341:627060] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Secret may not be nil when storing an object securely' *\ First throw call stack: (0x221ef86b 0x33ba2dff 0x221ef741 0x22f7f2ab 0x99361 0xc4825 0x2631956d 0x2631930f 0x269e4ced 0x269e4dc5 0x269ec5bd 0x26a8e757 0x26a8fcff 0x26a8f769 0x26a8b975 0x262fd6ab 0x25bc967d 0x25bc4d79 0x25bc4c09 0x25bc4129 0x25bc3deb 0x25bbd5bf 0x221b20f1 0x221b03e7 0x22103209 0x22102fdd 0x2b3a7af9 0x2636817d 0x9cc9d 0x342cd873) libc++abi.dylib: terminating with uncaught exception of type NSException
You first need to set a secret:
[[NSUserDefaults standardUserDefaults] setSecret:@"your_secret_goes_here"]
Otherwise encryption/decryption will fail.
Thanks for the reply. I had added that but code but in login where i'm doing the user data saving work. But now i have added that code in app delegate. So my problem got solved.
I have running in Xcode 6.3 and ios 8.3 .I tried to save the normal string in secure way i got below error:
2015-06-08 15:32:06.296 MyApp[2019:764561] *\ Assertion failure in -[NSUserDefaults setSecretObject:forKey:], /Users/irshadpc/Desktop/iOS/NSUserDefaults+SecureAdditions.m:190 2015-06-08 15:32:06.300 MyApp[2019:764561] Secret may not be nil when storing an object securely