gpt4 book ai didi

ios - 为什么在旧设备上首次打开时将预填充的数据库加载到核心数据时应用程序崩溃?

转载 作者:行者123 更新时间:2023-11-29 10:56:55 25 4
gpt4 key购买 nike

在我的应用程序中,我有一个预填充的 sqlite 数据库,它是使用我创建的另一个应用程序的核心数据创建的,因此数据模型是相同的。我把它复制过来,一切都很好。我在每个可以运行 iOS 6.0 的 iOS 设备上都尝试过它,因为这就是我正在构建的目标。即使在早期的 iPod Touch 上,该应用程序也能正常工作。数据库在旧设备上复制大约需要 45 秒。该应用程序运行所有数据,所有设备测试都很好,没有问题。我在应用程序商店发布了该应用程序,发现在旧设备上,该应用程序在首次加载时崩溃了。我假设这是一个内存相关的问题。我最困惑的是,与我联系的购买它的客户拥有同一部 iPhone 4S 手机,其中一位报告它工作正常,而另一位则说它崩溃了。我在想一个有早期的 4S,而另一个有一个较晚的 4S。我确认他们在手机上也有空间来复制数据。当我从 Xcode 运行应用程序时,无论使用何种设备,它都不会崩溃。

我的问题是有人知道为什么会发生这种情况以及可能的解决方法吗?

也许有一种更有效的方法,不会让应用程序在第一次加载时花费将近一分钟的时间?任何帮助都会很棒,因为我很茫然。我查看了大约 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

最佳答案

您正在主线程上复制数据,这会阻塞它太久。它永远不应被阻塞 1 秒或更长时间。否则 iOS 看门狗将终止您的进程。

具体的崩溃报告显示该应用程序被杀死,因为启动时间太长:com.JonPhillips.Upgrade 无法及时启动

复制操作甚至从 applicationDidFinishLaunching 内部运行。看门狗计时器甚至更短以结束此方法!如果您对 WWDC session 感兴趣,请查看确切的时间安排。我不记得具体在哪个地方提到过。

如果您需要此类任务,请将它们移至后台线程。如果此任务意味着用户无法在应用程序中执行任何操作,则显示一个特定的 UI 告诉用户正在发生什么,并给出一些指示需要多长时间,例如进度条,和/或一些文本“第 1 步,共 3 步:复制数据”。

关于ios - 为什么在旧设备上首次打开时将预填充的数据库加载到核心数据时应用程序崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17871500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com