Home > Enterprise >  Xcode migrate Core Data to new Bundle ID
Xcode migrate Core Data to new Bundle ID

Time:09-21

I want to change my bundle ID (just make it lowercase) because the bundle ID I set up in App Store Connect is all lowercase, but my old bundle ID in Xcode had an uppercase letter. Changing it in Xcode is straightforward, but when I run the app on my device, it installs a duplicate app instead of replacing the old version (because the bundle IDs have different capitalization). I'm using Core Data for my data persistence, and since I've been testing the app on my own device for a while and adding data through that, I would really like to keep the data I have but migrate it to the app with the new bundle ID.

All the related questions I've found so far are concerned with only changing the bundle ID, but not with maintaining the existing data. Is there a good way to do this?

CodePudding user response:

If you change the bundle ID, then it's a different app, as far as iOS is concerned. You have two different apps that happen to have similar bundle IDs, but they can't access each other's data any more than any two random apps can do that.

If you have not released your app, meaning it's still in development, you can copy data out of the old version and then upload it to the new version. You would use almost exactly the steps in this answer except that in your case you wouldn't delete the app until you were sure the copy was working normally. With these steps you basically copy the data from one version to your Mac, then copy it from the Mac to the other one.

If you have already shipped your app, it's more complicated. One way would be to update the app using the old ID but enable app groups. Have the update copy its data into the shared app group folder. Then enable app groups with the new ID and have it use the same shared folder. Another approach would be to have both versions sync data via some online service-- CloudKit, or Firebase, for example-- so that when the app gets the new ID it will get the new data by syncing it in.

  • Related