How to reinstall an app without losing NSUserDefaults? - ios

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?

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.

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

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.

Related

Xamarin IOS app, iCloud restore doesn't work once on App Store

My IOS app is now on the Apple App Store. I tested it like crazy before it was put on the App Store and I am sure Apple did as well, but now that it is on the App Store, when I install it from there, the restore function I wrote to restore the applications data from iCloud does not work. The backup function works, as I can see the iCloud usage on my phone for my app contains 78mb of data, but the restore does not work at all, it just goes back to the home page. I have no idea why as I get nothing reported on the crash.
2 questions
IS there a way to look at why it is crashing on my phone
Any idea why it would stop working once installed from the App Store when it must have worked for apple when they tested it and worked for me as well before on the App Store?
It turns out that I was mistaken about the restore failing. Well, it is failing, but the reason it is failing is because the backup is failing on each record, so nothing is created on iCloud to be read by the restore code. I have asked on a couple channels for help on what to do for writing to iCloud when the code is built in release mode, but have yet to receive any help. My code works perfectly in Debug, just not in release mode.

iOS app crashed even after reinstalled, but not for the new users

Some of my old app users are experiencing app crashes for a certain step after I updated the app. Even when they tried to delete the app and reinstalled it, it's still crashing. However, the app doesn't crash for new users.
How does that happen? When a user completely deletes the app and reinstalls it from the AppStore, the user should be like a new user, right? How come the new users don't crash while the users who re-install the app keep crashing?
Is there something remaining in the device even after the user deletes the app?
If you use keychain functionality that may persist across uninstalls and reinstalls. That, in theory, is the only data that should persist with that behavior.
Without more code or details it's hard to know what the problem might be, but to your question "Is there something remained in the device...": yes, keychain information.
One thing that does remain in the device after uninstalling an app is privacy settings (Relevant SO post).
Perhaps you're trying to access something incorrectly with your update?
Are you using any database in your project?
If yes we need to take care of version migration.

iOS: why some app can restore the account info when reinstalled

Some apps, If you have ever used it on your iPhone once and then uninstalled it, the next time you install the app, the app can still retrieve your info that you filled out before you uninstalled it last time.
How does the app do this?
It's because they save account information on the keychain.
Data stored in the keychain persist even if you uninstall the application, they are only removed if you perform a full restore of the device, or you remove by yourself.
This is a complete different behavior respect to NSUserDefault that is removed within the application deletion.
Data in keychain can also be shared between applications (if you implement it in the correct way) that use a similar bundle identifiers.

How to test local storage persistence after iOS App Store update?

At one point there was an AIR bug (3.5) that changed the location of the LSO storage, causing local SharedObjects to be "lost" after an app update. Apparently this issue was resolved in 3.6 and life goes on.
At this point I don't have 100% confidence that any user data stored in a SharedObject on an iOS device will persist after an AppStore update, and I would like to be able to test this out prior to actually submitting the update to Apple.
However, my experience has been than whenever you test/debug your app and a new IPA is generated, the old app is completely wiped, including all of its data. So there's no way that I know of that I can test an update of the app against an older version to ensure that the SharedOjbects remain accessible and working fine.
Are there any solutions? Or can anyone who's using LSO for persistent App data storage confirm that they've pushed an update through the App Store and retained saved user data?

Is it possible in iOS to detect if your App was updated?

Sadly, when my App is updated there is some saved data or left over logic that was already implemented. This can cause some bugs to occur. Is there a way to tell if an App was updated so I can make the user relogin? Any tips or suggestions are appreciated.
You can save the installed version in the NSUserDefaults. They will persist during app updates, so whenever your app launches you check for the saved version, compare it with the current version and do your migration if necessary. At the end, save the new version to the same key.

Resources