2012-04-13 10 views
1

Core DataとiCloudを使用して複数のiPads間でデータを同期するアプリケーションに取り組んでいます。これはすべて正常に動作していると私は各iPadにデータを追加することができますし、それらの間ですべての同期されます。Core DataとiCloud Pre-Populated sqliteファイルを追加する

私はCore Data sqliteファイルを持っています。このファイルには国のリストがあらかじめ入力されています。これをアプリケーションの最初の実行時にドキュメント領域にコピーします。私はこれを動作させましたが、persistentStoreCoordinatorの実装を変更してiCloudサポートの有無をテストし、その他いくつかの小さな変更を加えました。私はsqliteのファイルが存在するかどうかを確認し、それは私が

[psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:[NSURL fileURLWithPath:iCloudData] options:options error:&persistentStoreError]; 

NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:: CoreData: Ubiquity: An error occured while setting up the ubiquity integration: Error Domain=NSCocoaErrorDomain Code=134316 "The ubiquity container does not appear to match this persistent store, it is possible this is caused by switching to a different iCloud account, or logging out of iCloud entirely. The store should be re-opened with read-only attributes or removed from iCloud syncing permanently." UserInfo=0x1cb590 {storeUUID=31381598-EAFA-4550-9B96-F501800974D5, containerUUID=E3A8DC7D-41FD-405A-8D8A-C06C8B467CA2, NSLocalizedDescription=The ubiquity container does not appear to match this persistent store, it is possible this is caused by switching to a different iCloud account, or logging out of iCloud entirely. The store should be re-opened with read-only attributes or removed from iCloud syncing permanently.}

で次のエラーを取得しない場合は事前にsqliteのファイルをコピーする場合がありますので、しかし

は今、これですiCloudで、別のCore Data sqliteファイルまたはトランザクションログファイルへの参照がまだありますか?もしそうなら、どうすればそれらを取り除くことができますか?

答えて

4

事前作成されたコアデータストアをubiquityコンテナにコピーする必要はありません。これを行う古い方法は、シミュレータ/デバイス/コンピュータ上にSQLiteファイルを作成し、それを最初の実行時にコピーすることでした。 iCloudを使用している場合、これ以上行うことはできません。 iCloudは、変更のリストを「トランザクションログ」として受け取った各デバイスによって動作し、それがそれ自身のSQLiteストアに適用されます。それは何が変更されたのかを知る必要があり、.sqliteファイルを一括して取得してもそのことは分かりません。

これを行うためのiCloudの方法は、次のいずれかです。

  • はあなたのコード(例えばinsertStartData:メソッド)内から初期データを作成します。あなたはplist、または好きなものからそれを追加することができます。データが最初に存在していないことを確認する必要があります。
  • NSPersistentStoreCoordinatormigratePersistentStore:toURL:options:withType:errorを使用して、最初の店舗をコピーします。

Here's the docs:

You should not seed initial content with a prepackaged database file. Instead, you should create the default items in code, or use NSPersistentStoreCoordinator's migratePersistentStore:toURL:options:withType:error: method to migrate a prepackaged database to the required location.

+0

説明のための多くのおかげで、私は唯一のplistをより効率的になり、最初の起動時にcoredataに自分の緯度&長い二のと一緒に国(200&何か)のリストをインポートする必要がありますsqliteファイルをバンドルし、migratePersistentStoreを使用するよりも? –

+0

ええ、plistははるかに簡単です。まだインポートされていないことを忘れないでください。 –

+0

こんにちは、最初に実行するときにストアをテストするためにどのメソッドを使用する必要がありますか、また、ネストされたデータのJSONファイルがあります。 –

関連する問題