1

私のアプリには、作成した別のアプリのコアデータを使用して作成した事前設定済みの sqlite DB があるため、データモデルは同じです。私はそれをコピーし、すべてがうまくいきます。iOS 6.0 を実行できるすべての iOS デバイスで試してみました。それが私が構築しているものだからです。初期の iPod Touches でも​​アプリは動作します。DB が古いデバイスにコピーされるまでに約 45 秒かかります。アプリはすべてのデータがそこにあり、すべてのデバイスで動作し、テストは素晴らしく、問題はありませんでした. アプリ ストアでアプリをリリースしたところ、古いデバイスでは最初の読み込み時にアプリがクラッシュすることがわかりました。私はそれがメモリ関連の問題であると仮定しています。私が連絡を取り合っている購入した顧客が同じ iPhone 4S の電話を持っていて、1 人は正常に動作すると報告しているのに、もう 1 人はクラッシュすると報告しているので、私はほとんど混乱しています。4Sが早い方と4Sが遅い方がいると思います。電話にもデータをコピーする余地があることを確認しました。Xcode からアプリを実行すると、デバイスに関係なくクラッシュすることはありません。

私の質問は、これがなぜ起こっているのか、そして可能な修正を知っている人はいますか?

初めてアプリをロードするのにほぼ 1 分もかからない、より効率的な方法があるのではないでしょうか? 私は途方に暮れているので、どんな助けも素晴らしいでしょう。この質問に似た他の約30の質問を見ましたが、私が必要とする質問に実際には答えていません.

また、私はこのサイトに住んでいて、すべての質問と回答から多くのことを学んだので、あなたのすべてに感謝したいと思います.

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (_persistentStoreCoordinator != nil) {
        return _persistentStoreCoordinator;
    }

    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Data.sqlite"];

#define UPGRADE_COPY_STORE_FROM_BUNDLE

#ifdef UPGRADE_COPY_STORE_FROM_BUNDLE
    if (![[NSFileManager defaultManager] fileExistsAtPath:[storeURL path]]) {
        NSString *dataPath = [[NSBundle mainBundle]pathForResource:@"Data" ofType:@"sqlite" inDirectory:nil];
        NSError *anyError = nil;
        BOOL success = [[NSFileManager defaultManager] copyItemAtPath:dataPath toPath:[storeURL path] error:&anyError];
        if (!success) NSLog(@"Error copying file: %@", anyError);
    }
#endif


    NSError *error = nil;
    _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {

        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);

    }    

    return _persistentStoreCoordinator;
}

デバイスからのクラッシュ ログも添付されています。更新しました

    Incident Identifier: CCFB748D-5A2A-45CE-B9EC-19811CCDC696
CrashReporter Key:   71b2c2b3b88abfe03baa87e7f588642dcec0ff08
Hardware Model:      iPod4,1
Process:         Upgrade [2513]
Path:            /var/mobile/Applications/27C440D4-0210-48BB-A287-570FAEDE3369/Upgrade.app/Upgrade
Identifier:      Upgrade
Version:         ??? (???)
Code Type:       ARM (Native)
Parent Process:  launchd [1]

Date/Time:       2013-07-27 23:23:57.479 -0600
OS Version:      iOS 6.1.2 (10B146)
Report Version:  104

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

Application Specific Information:
com.JonPhillips.Upgrade failed to launch in time

Elapsed total CPU time (seconds): 2.450 (user 2.450, system 0.000), 12% CPU 
Elapsed application CPU time (seconds): 0.528, 3% CPU

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0:
0   libsystem_kernel.dylib          0x39b84570 read + 8
1   libcopyfile.dylib               0x39a70df4 copyfile_internal + 4616
2   libcopyfile.dylib               0x39a72196 copyfile + 3326
3   Foundation                      0x32301cb4 -[NSFilesystemItemCopyOperation _handleFTSEntry:] + 384
4   Foundation                      0x323014a2 -[NSDirectoryTraversalOperation main] + 334
5   Foundation                      0x322af5bc -[__NSOperationInternal start] + 836
6   Foundation                      0x322fdd1e -[NSFileManager copyItemAtPath:toPath:error:] + 238
7   Upgrade                         0x0009f438 -[JPPAppDelegate persistentStoreCoordinator] (JPPAppDelegate.m:186)
8   Upgrade                         0x0009ef30 -[JPPAppDelegate managedObjectContext] (JPPAppDelegate.m:150)
9   Upgrade                         0x0009f95e -[MainScreenViewController viewDidLoad] (MainScreenViewController.m:35)
10  UIKit                           0x33849590 -[UIViewController loadViewIfRequired] + 360
11  UIKit                           0x338c3fb8 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 80
12  UIKit                           0x338c3f5e -[UITabBarController transitionFromViewController:toViewController:] + 26
13  UIKit                           0x3386e05c -[UITabBarController _setSelectedViewController:] + 292
14  UIKit                           0x3386e642 -[UITabBarController _selectDefaultViewControllerIfNecessaryWithAppearanceTransitions:] + 150
15  UIKit                           0x338c6ca2 -[UITabBarController viewWillAppear:] + 130
16  UIKit                           0x3389130c -[UIViewController _setViewAppearState:isAnimating:] + 132
17  UIKit                           0x33849e10 -[UIView(Hierarchy) _willMoveToWindow:withAncestorView:] + 504
18  UIKit                           0x3382c40e -[UIView(Internal) _addSubview:positioned:relativeTo:] + 326
19  UIKit                           0x3382c2be -[UIView(Hierarchy) addSubview:] + 26
20  UIKit                           0x33889e46 -[UIWindow addRootViewControllerViewIfPossible] + 270
21  UIKit                           0x33885ae8 -[UIWindow _setHidden:forced:] + 360
22  UIKit                           0x338c71e4 -[UIWindow makeKeyAndVisible] + 56
23  Upgrade                         0x0009e896 -[JPPAppDelegate initializeStoryBoardBasedOnScreenSize] (JPPAppDelegate.m:64)
24  Upgrade                         0x0009e106 -[JPPAppDelegate application:didFinishLaunchingWithOptions:] (JPPAppDelegate.m:22)
25  UIKit                           0x3388aad4 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 248
26  UIKit                           0x3388a65e -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1186
27  UIKit                           0x33882846 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 694
28  UIKit                           0x3382ac34 -[UIApplication handleEvent:withNewEvent:] + 1000
29  UIKit                           0x3382a6c8 -[UIApplication sendEvent:] + 68
30  UIKit                           0x3382a116 _UIApplicationHandleEvent + 6150
31  GraphicsServices                0x3551a5a0 _PurpleEventCallback + 588
32  GraphicsServices                0x3551a1ce PurpleEventCallback + 30
33  CoreFoundation                  0x319f7170 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 32
34  CoreFoundation                  0x319f7112 __CFRunLoopDoSource1 + 134
35  CoreFoundation                  0x319f5f94 __CFRunLoopRun + 1380
36  CoreFoundation                  0x31968eb8 CFRunLoopRunSpecific + 352
37  CoreFoundation                  0x31968d44 CFRunLoopRunInMode + 100
38  UIKit                           0x33881480 -[UIApplication _run] + 664
39  UIKit                           0x3387e2fc UIApplicationMain + 1116
40  Upgrade                         0x0009e0b8 main (main.m:16)
41  libdyld.dylib                   0x39accb1c start + 0

Thread 1 name:  Dispatch queue: com.apple.libdispatch-manager
Thread 1:
0   libsystem_kernel.dylib          0x39b83648 kevent64 + 24
1   libdispatch.dylib               0x39abc4ec _dispatch_mgr_invoke + 792
2   libdispatch.dylib               0x39aaedf4 _dispatch_mgr_thread$VARIANT$up + 32

Thread 2 name:  WebThread
Thread 2:
0   libsystem_kernel.dylib          0x39b82eb4 mach_msg_trap + 20
1   libsystem_kernel.dylib          0x39b83048 mach_msg + 36
2   CoreFoundation                  0x319f7040 __CFRunLoopServiceMachPort + 124
3   CoreFoundation                  0x319f5d9e __CFRunLoopRun + 878
4   CoreFoundation                  0x31968eb8 CFRunLoopRunSpecific + 352
5   CoreFoundation                  0x31968d44 CFRunLoopRunInMode + 100
6   WebCore                         0x3794c500 RunWebThread(void*) + 440
7   libsystem_c.dylib               0x39aec30e _pthread_start + 306
8   libsystem_c.dylib               0x39aec1d4 thread_start + 4

Unknown thread crashed with unknown flavor: 5, state_count: 1
4

1 に答える 1

2

メインスレッドでデータをコピーしているため、ブロックが長すぎます。1 秒以上ブロックされることはありません。そうしないと、iOS ウォッチドッグがプロセスを強制終了します。

特定のクラッシュ レポートは、起動に時間がかかりすぎたため、アプリが強制終了されたことを示しています: com.JonPhillips.Upgrade failed to launch in time.

コピー アクションは内部から実行されていapplicationDidFinishLaunchingます。このメソッドを終了させるため、ウォッチドッグ タイマーはさらに短くなります。興味がある場合は、WWDC セッションで正確なタイミングを確認してください。具体的にどこで言及されたかは覚えていません。

そのようなタスクが必要な場合は、それらをバックグラウンド スレッドに移動します。このタスクがユーザーがアプリで何もできないことを意味する場合は、何が起こっているかをユーザーに伝え、進行状況バーやテキスト「ステップ 1/3」などの所要時間を示す特定の UI を表示します。 : データをコピーしています」.

于 2013-07-28T11:57:47.060 に答える