[NSUserDefaults standardUserDefaults] stopped working using iOS 9.3.1

I'm using this code in my app:



if ([[NSUserDefaults standardUserDefaults] objectForKey:@"First_RUN"] == NULL) {

[self tutorial:nil];

[[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"First_RUN"];

[[NSUserDefaults standardUserDefaults] synchronize];

}



I'm using this code to know when the first time the app runs, if that is the case I show a tutorial.

After upgrading to 9.3.1 I found out that it stopped working so that every time the app runs tutorial appears.

Tried to debug this but it seems that [NSUserDefaults standardUserDefaults] just stopped working.



I'm using old Xcode for this app (6.4). Any help using [NSUserDefaults standardUserDefaults] in another way or explanation for this issue would help (I have this kind of code in many of my apps and it all breaks now).

Replies

UPDATE: I created a test project for that (to isolate the issue), and it seems that simulator is fine but running on device with 9.3.1 even using Xcode 7.3 makes same issue.


I guess it is just broken with 9.3.1 !

After upgrading to 9.3.1 …

From 9.3? Or from some earlier 9.x?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I'm expereience with the same bug.

All stored data in NSUserDefaults is deleted every day after upgrading from 9.2.1 to 9.3.1.

In another thread there's a discussion about the same issue: https://forums.developer.apple.com/thread/44264


There's a suspicion: iOS 9.3 does not really delete the NSUserDefaults, but only forgets to load the data. If you can prevent that the App will save any new data in NSUserDefaults when this happens (usually only possible when debugging your own Apps in XCode), kill the App and restart, the settings are usullay loaded fine this time. But in real world scenarios you can't prevent that Apps will save anything in NSUserDefaults after this iOS bug shows up, and as soon as an App saves anything in NSUserDefaults, the old settings are overwritte, lost and really deleted.


I've seen this issue in several Apps now, so this gets really annoying...

Anyone have any joy? I'm still seeing it in iOS 10.1 😟


Just posted some interesting things I've seen here: https://forums.developer.apple.com/message/135342


Including the very odd thing I saw today where data from 2 years ago, that had been very much deleted, was resurrected in one of my apps... is iCloud misbehaving??

This is also happening for me as well. Data that I've set the previous app start is vanished the next time. It doen't happen all the time and also other apps are affected (like Whats App, Slack, Youtube, ...)

Other users have the same problem: https://forums.developer.apple.com/thread/44264


Today in the log concole of my app I found the following:

[User Defaults] Failed to write value for key <***> in CFPrefsPlistSource<0x17011b240> (Domain: <***>, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null)): Path not accessible, switching to read-only

Might have something todo with it?


Would be really great if somebody could really fix that bug. It anoys me since about a year... With long times inbetween beeing fine, but then comming back again 😟 like currently...