iOS 10, NSUserDefaults Does Not Work

纵然是瞬间 提交于 2019-11-27 14:38:48

I just had the same problem. There seems to be an issue with NSUserDefaults when first running the iOS8 or 9 simulator and then the iOS10 simulator. Rebooting the mac solved the issue for me.

This was a bug with the iOS Simulator that shipped with Xcode 8 Beta 1. It has been fixed in Beta 2:

Resolved in Xcode 8 beta 2 – IDE

Simulator

  • NSUserDefaults function correctly in the iOS 10 Simulator, regardless of whether you have previously booted the iOS 8 or iOS 9 Simulator. (25974372)

Xcode 8 Beta 2 Release Notes

Update to Xcode 8 Beta 2 to avoid having to restart your host Mac every time.

Update:

If data protection is enabled, synchronize may also fail when an application enter background.


We have this issue on a real device running iOS 10.1.1. Old value could be read, but new change cannot save to disk, synchronize method always fail.

Reboot the device may solve this issue.

I just had the same problem. There seems to be an issue with NSUserDefaults when first running the iOS8 or 9 simulator and then the iOS10 simulator. Rebooting the mac solved the issue for me. shareeditflag Confirmed. Closing and reopening the simulator didn't work, but rebooting fixed it for me.

As per Apple (apple link ) WWDC Seed: Running multiple iOS simulators can cause NSUserDefaults to not work Running an iOS 8 or 9 simulator followed by an iOS 10 simulator will cause NSUserDefaults to stop working in the simulator. This can be worked around by rebooting the host Mac.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!