I just noticed that the key that exists in my **NSUserDefaults** often returns zero. It seems that in about half of the cases itβs right, and the other half doesnβt. I say half the time, but I do not mean that it flip-flopping, its only 40-50%, I see that it does not work. When I write the initial value, I immediately call the synchronization. I use this key as an application revision, which I installed when a new user signs up.
The following code returns nil:
#define kDBrevision @"revision" NSString *rev = [[NSUserDefaults standardUserDefaults] objectForKey:kDBrevision];
When I run the application and simply track the value (without writing down any NSUserDefaults), sometimes this value is without any changes to NSUserDefaults.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSString *r = [[NSUserDefaults standardUserDefaults] objectForKey:kDBrevision]; NSLog(@"revision %@", r); _exit(1);
I have no idea why this is happening. Im running iOS 10 on my device connected to Xcode 8.2.1. Does anyone have any ideas? Thanks
EDIT: I started talking with an apple about fixing this and found out that if you have file protection completed, this might be the cause of this problem from time to time, however the apple told me that my special case (which is the only one on which I was sure at this time) is a mistake. The fact is that you use Xcode to run the application on the device, which should not be the way it sometimes happens. I do not know when and if to be fixed. Instead, I moved my critical strings from the defaults, using a keychain instead.
source share