3

I recently updated my app with a new version in app store.My users experienced a crash after updating the app.If the user deletes the older app and downloads the app as a new app from the store the app works as desired.

The change i have done is included a new entity in my core data file for a functionality which is located in documents directory in the sandbox compared to older version.When the app is updated from the app store will the core data file be updated with new entities and properties?

In simulator if i include a new entity and run the app without removing build the app crashes and the crash gets resolved if i remove the build and run it again.

I hope this(New core data entity) is the cause for the crash when updated from the store.Could someone suggest how to overcome this.When the user updates the app, the core data file should be also updated.. How can i implement this plz help.

Thanks in advance.

Dinakar
  • 1,198
  • 15
  • 37

1 Answers1

7

If you change the database structure across version, you must add database migration logic in your code. You can't just expect app to automatically work across different database versions.

Read this stackoverflow post which gives you some useful informations.

Apple's documentation about the subject is here. A good tutorial here.

Community
  • 1
  • 1
Krishnabhadra
  • 34,169
  • 30
  • 118
  • 167
  • Now if i upload a new version with the mentioned fix to appstore, Does my user able to update their device with new version and use it(I want to know whether the crash is fixed by the new version). – Dinakar Oct 16 '12 at 11:01
  • 1
    I have done migartion in xcode and didn't make any code changes..I added a new version from editor and pointed the version to new one.In my appdelegate there is already few statements stating the Persistant store to check DB version by passing a dictionary as mentioned in the post you linked...will this work?Plz help – Dinakar Oct 16 '12 at 11:03
  • You can test it yourself before submitting to app store.. If you have your old project code with you (svn may be) build and run it into your device. Run the app, add some data to datastore.. Then take your current project and run it into the device without deleting the old version.. See if it is crashing.. – Krishnabhadra Oct 16 '12 at 11:08
  • Tnq for the reply.I have done exactly the same and it is working.But will the same happen if an version is updated from appstore.I guess update doesn't change the file system contents of sandbox.Please can u explain what exactly happens when a update is done to the app.One more query is my code has two .xcdatamodel files in my project and whenever i make changes to the DB a new .xcdatamodel file gets created.Doesn't it create duplicate files and would it cause any adverse issues in future.Plz share your thoughts they are valuable to me...TNQ – Dinakar Oct 16 '12 at 12:09
  • @efrank I am not that much familiar with core data but more with old sqlite usage in iphone. When you update an app from store (without deleting the old version you already have in device) datas stored in backend (NSUserDefault, database etc) will not get deleted, only the app build get replaced. When you run the new version,the existing app expect data model of a different kind (data model of your new database structure) but existing one is different. This caused the exception which you encountered. – Krishnabhadra Oct 16 '12 at 12:14
  • I believe when you do migration , you get 2 .xcdatamodel files.. But as I already said, I am not that much familiar with core data migration.. I think the apple documentation covers all that.. Cant help you much there.. Sorry.. – Krishnabhadra Oct 16 '12 at 12:16
  • Its ok.But my critical issue was rectified with ur answer.Tnx once again..i will find more details with that knowledge.. – Dinakar Oct 16 '12 at 12:44