Force iOS app's database to upgrade - ios

My app's 2nd version adds two new entries to the database. But the new items are only gets listed in the app's table view if I uninstall the app from the phone and install the new version. Otherwise the new entries are not getting updated to the DB. Entries are listed in a plist file.
How do I force it to update the DB (without losing data) ?
Thanks in advance.

You need to have some kind of version identifier in your database, and when you app launches, always check it. If you find it is an older version, add the additional data that needs to be added than update the version number. This means that your plist needs to keep track of what is new by database version.
Note that the lack of a version identifier can be treated as a version identifier (that is null is older than version 1).

Related

Replace core data model in new version of app without having previous source code

Hi I struck at core data migration issue. I have developed a app which is new version of an existing app in Appstore. But i don't have source code of previous version and don't know exactly that whether core data was used in old version or not. So how to update my app (which has core data) to Appstore without any crashes. Any quick solution please?
Since you mention in a comment that you want to ignore the old data, you don't need to do any kind of migration. Model migration is about updating existing data to work with a newer data model. The only danger would be if the old app used Core Data and your new app attempts to use a persistent store file with the same file name. Then your app would attempt to load the old data, since it would find that file with the correct name.
The easiest way to test this is:
Install the existing app (from the app store)
Use this app until you're sure it's saving some data
Install the new version from Xcode. Since it's an upgrade, it will overwrite the app store copy.
By then you'll know exactly what happens when upgrading. If you get a Core Data related crash, change your Core Data setup to use a different filename. Then delete the app from your iOS device and repeat the test from above.

Can't save changes in Realm DB file

I work in iOS app and I use Realm for local DB. I've installed Realm via cocoapods and added my model classes. Everything is fine but when I opened the default.realm file from the simulator Documents directory in Realm browser app, I was unable to edit records or do any changes. I'm able only to add records but I can't edit fields, once I put the value in fields and navigate between classes, all changes I made disappear.
Update:
I see in cocoapods, the RealmSwift installed is version (0.98.3) and the Realm browser which is the latest from App Store is version Version 0.97.0 (62). Would that be the problem?
If you double-click on a field, that should make the cell editable and you can change it's values. It might be necessary to hit 'Return' after you've made those changes for the value change to stick.
There's a new version of the Browser on its GitHub page now: https://github.com/realm/realm-browser-osx/releases/tag/0.98.3
If you're still having issues with that version and the instructions I provided above, please let me know here!

How to fix crash when modifying Core Data with a new version of an app in iOS

I am struggling with an issue related to Core Data.
In my app, I use Core Data for storing and retrieving the values. In my latest version, I added some attributes to entities from the old version. I updated the app from the App Store, and when I click on the page where we need to display the contents from Core Data, it is crashing.
If the old version of the app is removed and the new one is downloaded, then it doesn't crash.
My requirement is any alternative there is to fix without having to remove the old version of the app (merging the old version with the new version).
Any suggestions on how to fix this issue?
Thanks in advance.
Did you setup versioning of core data? IF so, in your Xcode project navigator, your .xcdatamodeld should be drop down with multiple .xcdatamodeld underneath it. And then in attribute inspector with the parent .xcdatamodeld selected you pick your current version.
If the changes are minor, this will take care of it's self when you load new app version ontop of older version.
If the changes are major, you need to setup handling for this in your app delegate to tell the app how to move data between the two versions.
You have to migrate the Core Data store from the old Version to the new one.
This tutorial show's how this works: http://www.raywenderlich.com/27657/how-to-perform-a-lightweight-core-data-migration

iOS app behaviour after installing new version from app store

I have an iOS app installed in iPhone from app store, now if I have an updated version 1.1 for the same app at app store and I'm getting some sort of informative alert from the older version 1.0 (New version is available...).
If I click on alertview's ok button, it redirects me to the new app link in browser. I download my new version then.
Please provide answers of following questions :
Will it replace old version?
Will it replace sqlite and image folder on the document path? (Both version is having same named sqlite file, say abc.sqlite1.0 and same folder name, say imagesToBeCopied)
Will it append the sqlite entitie rows with new rows for same entity?
How can I install version 1.0 again from app store? Is it possible to get it anyhow?
Please provide your valuable answers on it, which can help me out to reach to some solution.
Thanks.
1.Will it replace old version?
Yes, the app bundle will be replaced by the new one
2.Will it replace sqlite and image folder on the document path? (Both version is having same named sqlite file, say abc.sqlite1.0 and same folder name, say imagesToBeCopied)
No, the documents directory is not affected by the update process. If you have procedures in your code that update the documents directory, they will still run, but without any changes it would be no different to a normal launch of your app - e.g. if you check for and copy if needed, something from the bundle to the documents directory, this will only happen if the target file doesn't already exist.
3.Will it append the sqlite entitie rows with new rows for same entity?
This is not related to the update process. If you want to modify the data as part of the update, you will write this specifically in first launch code for your new version.
4.How can I install version 1.0 again from app store? Is it possible to get it anyhow?
No, the updated version replaces the old one on the app store.
To the best of my knowledge...
Yes, the new version of the app will replace the old version.
Yes it will replace your sqlite file, assuming your paths did not change across versions. If you want to handle this sort of case it is your responsibility to include logic in the newer version of the app to check for the existence of the sqlite file and overwrite or modify it accordingly.
No, all modifications to the sqlite file need to be done manually by the new version (see #2).
As of now, not possible to do this through the app store. Only one version of any app can be placed for "sale" at a time. You would have to do this through other means (testflightapp.com for instance [for adhocs for devs]).

App Store release using wrong Core Data Version

My released version appears to be using a old model version of Core Data, xxxDB 101j instead of xxxDB as defined in the VersionInfo.plist (package contents of xxx.xcarchive submitted to the app store). This has not been an issue on development devices or releases to TestFlight.
It is using the last listed version in VersionInfo.plist, not the version defined in the NSManagedObjectModel_CurrentVersionName property. Interestingly all the versions have a .mom file including xxxDB but xxxDB also has an .omo file as well.
Has anyone bumped into this issue and found a work around?
The workaround is to add a new version model, make that the current version, clean, archive and submit. At this point in time, the NSManagedObjectModel_CurrentVersionName property is not used when your app is submitted to the app store. It uses the last listed model in the VersionInfo.plist.
The behavior in the testing/adhoc environment is different to go live

Resources