How to reinstall an app without losing NSUserDefaults?

旧城冷巷雨未停 提交于 2019-12-25 17:06:25

问题


I have an iOS game that saves game progress using NSUserDefaults. After the last update a user had a problem, the app was not working anymore on this device. The app doesn't have any problem, but for some reason an error occurred while downloading the app, not quite sure what happened.

The point is, the app must be deleted and reinstalled. Can this be done without erasing NSUserDefaults?

I tried syncing with iTunes here after deleting the app, even installing it again through iTunes but I was unable to restore the previous saved game on my test devices.

I guess the only way to reinstall the app is through an app update. When it comes out he will update and will not lose any data. Is this correct? Or is there any other way to do this?

I'm working to implement cloud syncing on the next update, so this problem should not be an issue again :). But right now, is there anything and I do to this user?


回答1:


Cloud sync would be the solution. If you using your iPhone only once the app is deleted every thing related to it is gone with no easy way to retrieve it.




回答2:


Or just store data that needs to be persistent in the keychain.




回答3:


Restoring the device from an iTunes Backupd probably reinstalls the app and also keeps the NSUserDefaults, assuming they are included in the backup.

However, this needs to be done by the user ... Some syncing option is the better solution on the long way.



来源:https://stackoverflow.com/questions/15446443/how-to-reinstall-an-app-without-losing-nsuserdefaults

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