NSUSERDefaults MBS

I am having trouble resetting the NSUserDefaults on my iMac M2. I was doing the following to keep track of an IAP which I thought was working but now it always remains TRUE. I have tried restarting but no use. Is there a way to delete/reset that setting?

I tried but same result
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
u.resetStandardUserDefaults

//Setting
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
u.setStringValue “au.com.rushsoftware.ClozeWizard.CWIAP001”, “TRUE”

//Reading
Const purchaseID = “au.com.rushsoftware.clozewizard.CWIAP001”
App.IsPurchaseMade = NSUserDefaultsMBS.standardUserDefaults.BoolForKey(purchaseID)

//Resetting for further testing
dim u as NSUserDefaultsMBS = NSUserDefaultsMBS.standardUserDefaults
u.setStringValue “au.com.rushsoftware.ClozeWizard.CWIAP001”, “FALSE”

Check the host. The code should have the “any host” set. Or the prefs get confusing between app store and non-app store. Been there - done that - got the t-shirt after wasting 30 minutes.

Preformatted texttheCFPrefs.kCFPreferencesCurrentUser, theCFPrefs.kCFPreferencesAnyHost

Hi Beatrix,

Not sure what that means, this is my first time trying to set values in user defaults

https://developer.apple.com/documentation/foundation/nsuserdefaults/1407708-resetstandarduserdefaults

It says “This method has no effect and shouldn’t be used.”

You should just be able to remove the key or do it from a command line using the defaults command.

1 Like

Thanks Beatrix, worked it out in the end