OS X UserDefaults file location

Hello! Where can I find file with current UserDefaults data in OS X? I want to remove all data.

getWriteablePath()

It returns my documents directory, but I can’t find some cocos2d-x file here. It contains only few my own files.

Depends on which version of Cocos you are using. In older versions there was a file UserDefault.xml, stored in getWriteablePath(), but newer versions use the systems UserDefaults methods. I’m not sure when the switch occurred. If you are using an older version then just delete that file and purgeSharedUserDefault(). If you are using the newer version, then you need to make a native call to

[[NSUserDefaults standardUserDefaults] resetStandardUserDefaults]; 

Maybe a call to reset should be added to Cocos’s UserDefault.

1 Like

I use 3.4 and this version already have switched to NSUserDefaults. I tried to find file with NSUserDefaults data in ~/Library/Caches and ~/Library/Preferences without result. I would try to find place for inserting

[[NSUserDefaults standardUserDefaults] resetStandardUserDefaults];

Thank you for suggestion.

Well, I found soliton.

NSString *domainName = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:domainName];

I have inserted this code to constructor of UserDefault class in UserDefault-apple.mm file.
Of course it’s temporary solution just for one build, but it works!

Thank you very much!

1 Like