0

に永続ストアを作成するアプリがありますapplication:didFinishLaunchingWithOptions。ストアの追加には明らかに時間がかかりすぎる可能性があります。そのため、iOSは起動が完了する前にアプリを終了します。タイムアウト時のスタックトレースは次のようになります。誰かがこれが起こるのを防ぐ方法を知っていますか?

Exception Type:  00000020
Exception Codes: 0x000000008badf00d
Highlighted Thread:  0

Application Specific Information:
com.foo.bar failed to launch in time

Elapsed total CPU time (seconds): 23.490 (user 23.490, system 0.000), 78% CPU 
Elapsed application CPU time (seconds): 8.406, 28% CPU

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0:
0   libsystem_kernel.dylib          0x31b8939c pread + 20
1   libsqlite3.dylib                0x31ed95d0 unixRead
2   libsqlite3.dylib                0x31eec106 readDbPage
3   libsqlite3.dylib                0x31eeb2a2 sqlite3PagerAcquire
4   libsqlite3.dylib                0x31f04096 moveToChild
5   libsqlite3.dylib                0x31f052c6 sqlite3BtreeNext
6   libsqlite3.dylib                0x31f01490 sqlite3VdbeExec
7   libsqlite3.dylib                0x31efa48a sqlite3_step
8   CoreData                        0x364f8892 _execute
9   CoreData                        0x364f878c -[NSSQLiteConnection execute]
10  CoreData                        0x3658bd94 -[NSSQLConnection prepareAndExecuteSQLStatement:]
11  CoreData                        0x365dd4f2 -[_NSSQLiteStoreMigrator performMigration:]
12  CoreData                        0x365d70dc -[NSSQLiteInPlaceMigrationManager migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:]
13  CoreData                        0x36577428 -[NSMigrationManager migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:]
14  CoreData                        0x365c8670 -[NSStoreMigrationPolicy(InternalMethods) migrateStoreAtURL:toURL:storeType:options:withManager:error:]
15  CoreData                        0x365c79c4 -[NSStoreMigrationPolicy migrateStoreAtURL:withManager:metadata:options:error:]
16  CoreData                        0x365c8ece -[NSStoreMigrationPolicy(InternalMethods) _gatherDataAndPerformMigration:]
17  CoreData                        0x364ec3b0 -[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:]
4

2 に答える 2

4

badfoodは、一般的な起動クラッシュです。メインスレッドからCoreDataスタックの作成を取得する必要があります。私は過去にここや他の場所でこれについて数回議論しました。

また、起動コードが問題を解決するので、AplleのiCloudCoreDatavidrosを見ることができます。

スタックを配置せずにアプリを起動できる必要があることに注意してください。既存のアプリの場合、これは大きな変更になる可能性があります。

アップデート2

これは常に推奨されてきましたが、残念ながら、テンプレートに表示され始めたのはごく最近のことです。

永続ストアの追加に時間がかかる原因となるものがいくつかあります。

  1. データベースをあるバージョンから別のバージョンに移行する場合。ストアをコーディネーターに追加すると、移行が発生します。
  2. アプリケーションにiCloudを追加する場合は、最初の起動時にかなり時間がかかります。
  3. Core Dataが、メンテナンスのためにデータベースに対して何かを行う必要があると判断した場合、予想よりも時間がかかる可能性があります。

「正しい」答えは、メインスレッドから離れたコーディネーターにストアを追加することです。

迅速な/簡単な答えは、コアデータのSQLロギングをオンにして、起動中に何が起こっているかを確認することです。遅延の原因を理解したら、それに対処できる可能性があります。それが移行である場合、正しい答えがおそらく唯一の答えです。

アップデート3

  1. これを機器でプロファイリングします。それは遅さがどこにあるかを教えてくれます。
  2. 何をしdataToMigrate = [self fetchSomeDataFromDatabase];ますか?

あなたの時間プロファイルを見てください、そしてそれはあなたに何が遅いかを教えてくれます。楽器からの時間プロファイルを送ってください。私もそれを見ていきます。

于 2012-11-11T18:21:38.913 に答える
0

コードは簡単です:

    dispatch_async(DISPATCH_QUEUE_PRIORITY_HIGH, ^{
        [self setupCoreDataStack]; //TODO
    })

しかし、マーカスが言ったように、起動時にCoreDataの準備ができていないことをアプリが処理できることを確認してください(現在は非同期です)..たとえば、スプラッシュ画面を設定できます!?/データベースを使用しない基本メニュー

于 2012-11-11T18:59:58.557 に答える