LoginSignup
0
1

More than 1 year has passed since last update.

CoreDataをiCloudと連携させてアプリをリリースしたら、本番環境で連携できてなかった話

Posted at

開発中はiCloudと連携していることは確認できていたので、アプリを再インストールした時にデータが復活していた。アプリの審査が通って手元でリリースアプリを動かしたところ、再インストール時にデータが復元できなくてめちゃくちゃ焦りました・・・

調べたところCloudKit Databaseのサイトにログインして、
Deploy Schema Changesというのをクリックして本番環境でもiCloud連携ができるように設定が必要でした。

しかし、クリックしたところエラーメッセージが表示。

スクリーンショット 2023-04-21 20.21.46.png

Schema uuid stale, please fetch latest schema.という謎のエラーが。
ググったところ色々情報が出てきて
initializeCloudKitSchema
の処理をすると直ると出てきたので試したところ

        container = NSPersistentCloudKitContainer(name: "hogehoge")
        container.loadPersistentStores(completionHandler: { (storeDescription, error) in
            if let error = error as NSError? {
                fatalError("Unresolved error \(error), \(error.userInfo)")
            }
        })
        container.viewContext.automaticallyMergesChangesFromParent = true
        // この2行を追加してエミュレーターで動かす。
        let options =NSPersistentCloudKitContainerSchemaInitializationOptions()
        try? container.initializeCloudKitSchema(options: options)

無事「Deploy Schema Changes」でエラーメッセージがなくなり本番環境でもiCloud連携が動くようになりました。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1