Automatically reset damaged NSUserDefaults

Is there a way to internally repair corrupted NSUserDefaults in iOS? For example, is there any particular exception that occurs in this case that I could then gracefully answer? I think some of my users are experiencing crashes on startup due to corrupt settings (they don't email me so I don't know the specifics) and it would be nice if my app could automatically reset NSUserDefaults when that happens ...

Related question: How can I intentionally corrupt NSUserDefaults to test this situation?


source to share

1 answer

I'll try with luck:

Try adding an object class check in NSUserDefaults

at startup. Therefore, before any of these are used in your code. Or check some other things depending on what should be in there.

And to "screw up" I would try to save NSArray

instead of NSNumber

eg. Then restart the application.

Hope it helps



All Articles