将应用程序发布到AppStore之后,如何更新CloudKit模式

发布于 2025-02-11 04:50:54 字数 1008 浏览 2 评论 0 原文

最近,我的一个生产应用程序遇到了一个问题,该应用程序使用核心数据 CloudKit ,其中数据在设备之间没有同步,经过一番研究,我发现需要初始化的私人CloudKit容器中的模式;我从来没有做过。

我仍然不是100%肯定的部分是何时运行 initaizecloudkitschema 方法,该方法已将应用发布到AppStore之后。我看到Apple建议在使用 #if debug 测试时运行它,但是...您每次在Xcode中编译时真的想运行它吗?

这是我在这一点上理解的方式...

  1. 应用程序版本,调用 initizecloudkitschema()以匹配 core> core data cloud> cloudkit 之间的模式。
  2. 添加或删除和属性,调用 initizecloudkitschema()以更新 Cloudkit schema。
  3. 重命名为属性,调用 initizecloudkitschema()以更新 CloudKit schema。 等等。

如果我上面的假设是正确的,请在开发过程中调用 prinitizecloudkitschema()方法,将在 cloudkit 中更新架构,然后在AppStore中发布新应用程序,因此创建对于使用该应用程序的先前版本的现有用户的问题,因为它们将没有最新的代码,但是将使用包含新属性的最新架构。

在将应用程序发布到AppStore之后,有人可以在 CloudKit 中分享其处理模式更新的方法吗?

代码:

do {
    try container.initializeCloudKitSchema()
} catch {
    print(error)
}

I recently had an issue with one of my production apps that use Core Data and CloudKit where data wasn't syncing between devices, after a little bit of research I found out that the schema in the private CloudKit container needed to be initialized; which I never did.

The part I'm still not 100% sure is when to run the initializeCloudKitSchema method after the app has been released to the AppStore. I see that Apple recommends running it when testing by using #if DEBUG, but... do you really want to run it every time you compile in Xcode?

Here is how I understand it at this point...

  1. App release, call initializeCloudKitSchema() to match schemas between Core Data and CloudKit.
  2. Added or deleted and attribute, call initializeCloudKitSchema() to update the CloudKit schema.
  3. Renamed an attribute, call initializeCloudKitSchema() to update the CloudKit schema.
    Etc.

If my assumption above is correct, calling the initializeCloudKitSchema() method during development would update the schema in CloudKit before the new app version is released in the AppStore, therefore creating an issue for existing users with previous versions of the app since they will not have the latest code but will be using the latest schema which contains the new attributes.

Can someone please share their method of handling schema updates in CloudKit after the app has been released to the AppStore?

Code:

do {
    try container.initializeCloudKitSchema()
} catch {
    print(error)
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝對不後悔。 2025-02-18 04:50:54

就我而言,我什至不需要运行 inationizecloudkitschema()方法。这是我所做的对我有用的。

  1. 我用两个设备在本地测试,并确保一切都按预期进行同步。当然,这是使用测试登录帐户在沙盒环境中在XCode中完成的。

  2. 然后我去了开发 CloudKit 容器,然后单击部署模式更改

  3. 最后,我使用生产/常规用户帐户直接在两个不同设备上的App Store下载了该应用程序,然后对其进行了测试。一切都按预期工作。

  4. 完成

理论上讲,一旦您对架构感到满意后,您似乎需要将架构部署到生产CloudKit容器,并通过执行上述或可能调用我没有尝试的initializecloudkitschema()。

旁注:一旦将模式部署到生产CloudKit容器中,您将不再删除或重命名实体或属性。另外,每次更新核心数据架构时,您都必须执行以上操作。请记住,如果您在核心数据中添加或删除实体或属性,则必须创建一个新版本的核心数据容器以执行所谓的光迁移。

编辑:这是如何创建核心数据容器的新版本。

  1. 打开XCode并选择核心数据容器。
  2. 转到编辑>添加模型版本。
  3. 输入新版本的名称。我使用以下命名惯例,核心塔纳克V2。我基本上将-vx添加到每个新版本。
  4. 在右侧打开文件检查器,并将“模型版本”下拉菜单设置为新的型号版本CoreDataContainer-V2。
  5. 去扩展核心塔替纳剂;请注意,现在它应该有两个容器,原始版本和新版本。确保选择了新版本。
  6. 添加您的新实体或属性。
  7. 测试并确保没有错误。
  8. 转到CloudKit并部署模式更改。
  9. 完毕。

In my case, I didn't even need to run the initializeCloudKitSchema() method. Here is what I did that worked for me.

  1. I tested locally with two devices and made sure everything was syncing as expected. This of course was done in Xcode within the sandbox environment using testing login accounts.

  2. Then I went to the development CloudKit container and clicked on the Deploy Schema Changes.

  3. Lastly I went and downloaded the app directly from the App Store on two different devices using a production/regular user account and tested it. Everything worked as expected.

  4. Done

In theory, it looks like you need to deploy the schema to the Production CloudKit container once you're satisfied with the schema and the results in the testing environments by doing the above or possibly calling the initializeCloudKitSchema() which I didn't try.

Side notes: It looks like once you deploy your schema to the Production CloudKit container you no longer can delete or rename Entities or Attributes. Also, you will have to do the above every time you update the Core Data schema. Keep in mind that if you add or remove Entities or Attributes in Core Data, you must create a new version of the Core Data container to do what is called a light migration.

EDIT: Here is how to create a new version of the Core Data container.

  1. Open Xcode and select the Core Data container.
  2. Go to Editor > Add Model Version.
  3. Enter a name for the new version. I use the following naming convention, CoreDataContainer-v2. I basically add -vX to every new version.
  4. Open the File Inspector on the right and set the "Model Version" drop-down menu to the new model version, CoreDataContainer-v2.
  5. Go and expand the CoreDataContainer; please note that now it should have two containers underneath, the original and the new version. Make sure the new version is selected.
  6. Add your new entities or attributes.
  7. Test and make sure there are no errors.
  8. Go to CloudKit and Deploy Schema Changes.
  9. Done.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文