ios how to manage DB with iphone app version by version? - ios

My question contains two ways:
1. For example I have an app which is on appstore and containing sqlite database. After sometime I want to update app version without changing database schema. what happened when app will be updated on user's device ? would all data in old database removed or just remains with same database and data ?
2.For example I have an app which is on appstore and containing sqlite database. After sometime I want to update app version with changed database schema. what happened when app will be updated on user's device ? its must changed the DB file but how can we save old data entries those are in old DB version. I have read many posts but still confused which approach I should use.
Thanks in advance for Helping

It is quite simple. When updating the application documents folder remains intact, so you can assume that the user data continues to be available.
For case 2 make sure you do not compromise the data in your update routines at the first start after the update. The app should detect that it is in a new version and modify the schema (e.g. via SQL scripts) while taking care of not deleting user data.

Related

If I upload a next version of ios app in app store, is my Old data will be deleted

I have one clarification, If I had upload a first version 1.0 of my app in ituenes app store and that app 100 users have been downloaded and using it, after one month I have added some extra features in the same app and uploading a next version eg: 1.2
Then The 100 users who have already using those application has been updated the next version.
My question is : In the first version if they have saved their data in
1. Nsuser Default
2. Core Data
Will it be deleted when updating the next version.
What will be the process, Some one could be explain.
When using Core Data if you have made changes to the data model then there are several possibilities.
First, if you don't do anything and just update the data model then when the update is applied to existing installs the app will crash when trying to access CoreData data. This is because the model it is expecting is different from the one in the database.
Second, you could get around this by manually deleting the core data store and setting up a new one. This will also get rid of all the data so possibly not a good solution.
Third, you can update your CoreData model version number. Instead of just changing the data model create a new version of the data model from the existing one.
Now, when the app detects that the data model and data do not match (like in the first version above) it will migrate the data from the old to the new version. Sometimes this is possible automatically but it may require some additional code from you to help it along.
This site goes into how the migration works... https://www.objc.io/issues/4-core-data/core-data-migration/

how i can avoid my data lost when i updates my apps in iOS?

When using PhoneGap, do users lose all of their saved data when they update an iOS app downloaded from iTunes?
I am hoping that anything stored in either Webstorage feature in Construct 2 will be preserved whenever someone downloads a new version of the app from iTunes, but I'm afraid to build a whole Apps only to have a bunch of upset users when they update the app. I know when I build an app in Objective C I have to go through some hoops to get the Core Data store to migrate correctly.
The other option is to mirror the data to an external server/database, but I want to avoid that expense and complication if I can.
If you change anything in the tables in CoreData then you would have to implement migration for the tables by creating a new version (check apple's documentation here: Lightweight Migration)
Otherwise if you don't change anything updating the app would not make the user lose any data.

Titanium Alloy on iOS: When a user gets an app update, it deletes and resets the local database

I've released a Titanium App on iOS through the App Store. It uses Alloy models, views and controllers and therefore saves all data that the user inputs via the Alloy .save() method. I've recently received some feedback from a user that after their most recent update, their data was wiped and none of their saved information was intact.
I thought that the Alloy database was saved into the private documents of the device, therefore keeping it intact when the user updates the app. Is that true?
What kind of things can I troubleshoot to see where I have gone wrong? I have not written any code that would remove anything from the database.
I thought that the Alloy database was saved into the private documents
of the device, therefore keeping it intact when the user updates the
app. Is that true?
That's correct.
I've recently received some feedback from a user that after their most
recent update, their data was wiped and none of their saved
information was intact.
It sounds like a whole database was removed. This may happen if you delete an application. I think you better test it by yourself. It is hard to help if we can't see any source code. I would also recommend you to look if there are no differences in Alloy (Maybe your updated version of the app uses newer version that is in something different)... maybe the data wasn't removed ,but was only changed the name of the database / tables. Hard to say...

Adding some but not all data from new app version’s database to existing database

I am creating a core data app with preloaded data using an SQL file. I am able to create the preloaded data, insert that SQL file into the project, and there is no problem. When users open the app for the first time the pre-populated store is copied over to the default store.
However, I am thinking ahead that in future versions I will want continue to add to this database. I will want users to be able download the current version with the latest DB without erasing user-generated data or user-edits to data in the preloaded DB.
This is not a migration issue because the model has not changed. Basically, when a new version of the app is opened for the first time I want it to check for the presence of new objects in the pre-populated store and add them to the user store. Any suggestions are welcome.
Make your preloaded data include, for each object, the version where that object was first added to the preload file. Then add new data by
Look up the previous app version in user defaults. Compare it to the current version. If they're the same, stop, otherwise continue to the next step. (If there is no previous version number, continue to the next step).
Fetch all objects that were added more recently than the saved version number from step 1.
Add those objects to the user's persistent store.
Update the app version in user defaults so it'll be current next time.
You can do this check every time the app launches. You'll want to save a numeric version number in user defaults that will always increase in future versions of the app.
The simple way to record the version info in the preload file is just to add an extra field on each entity type. A more elegant way would be to create a new entity called something like VersionWhereAdded that includes a version number and a to-many relationship to objects added in that version.

iOS App Store, forcing reinstall

Is there really no way of forcing an app update from the app store to do a complete reinstall? (say your database needs to be updated but you have no real need (or desire) to migrate existing data).
(I am wondering if the only way of getting a new version of an app on the device without the update function, is to complete remove the current app, give the updated (new) app a new namespace/identifyer and upload that from "scratch", and then hope the user will actually notice that the app is now a new app...).
Any suggestions?
Thanks in advance.
The 2nd option seems like a bad idea, users wont have any idea that your app has a new "version" so wont go looking for it, so you would have to send them notifications telling them about it. I cant imagine you'd get a huge percentage of people changing over
If all you need to do is delete the old database and start again you can do that. This question has an answer for an sqlite database. Basically you just need to keep track of which version of the model the user has, and when they upgrade, you delete the old one and set up a new database from scratch

Resources