FMDatabaseQueue 崩溃

FMDatabaseQueue crash

我在我的应用程序中使用 FMDB。我看到在应用程序启动期间发生了这种随机崩溃。

-(void) addActivities{
[[[DB sharedManager]getSecureQueue] inTransaction:^(FMDatabase * _Nonnull db, BOOL * _Nonnull rollback) {

        //process data
 }];
}

getSecureQueuereturns一个 FMDatabaseQueue:

_secureQueue= [FMDatabaseQueue databaseQueueWithPath:dbPath];

我检查过 _SecureQueue 不为零。

崩溃日志:

Crashed: fmdb.<FMDatabaseQueue: 0x170242610>
0  libdispatch.dylib              0x18ad83634 _dispatch_barrier_sync_f_slow + 560
1  FMDB                           0x101040bd8 -[FMDatabaseQueue beginTransaction:withBlock:] (FMDatabaseQueue.m:228)
2  FMDB                           0x101040bd8 -[FMDatabaseQueue beginTransaction:withBlock:] (FMDatabaseQueue.m:228)
3  iPhoneHandheldACT              0x1001e4870 -[HHCTabBarController addActivities] (HHCTabBarController.m:145)
4  iPhoneHandheldACT              0x1001e553c __49-[HHCTabBarController migrateIntoRealm]_block_invoke (HHCTabBarController.m:226)
5  FMDB                           0x101040ac4 __30-[FMDatabaseQueue inDatabase:]_block_invoke (FMDatabaseQueue.m:188)
6  libdispatch.dylib              0x18ad729a0 _dispatch_client_callout + 16
7  libdispatch.dylib              0x18ad7fee0 _dispatch_barrier_sync_f_invoke + 84
8  FMDB                           0x101040a34 -[FMDatabaseQueue inDatabase:] (FMDatabaseQueue.m:202)
9  iPhoneHandheldACT              0x1001e4ce8 -[HHCTabBarController migrateIntoRealm] (HHCTabBarController.m:181)
10 iPhoneHandheldACT              0x1001e4270 -[HHCTabBarController viewDidLoad] (HHCTabBarController.m:77)
11 UIKit                          0x191fecb04 -[UIViewController loadViewIfRequired] + 1036
12 UIKit                          0x192004590 -[UIViewController __viewWillAppear:] + 132
13 UIKit                          0x192188e18 -[UINavigationController _startCustomTransition:] + 1144
14 UIKit                          0x1920a37bc -[UINavigationController _startDeferredTransitionIfNeeded:] + 676
15 UIKit                          0x1920a3424 -[UINavigationController __viewWillLayoutSubviews] + 64
16 UIKit                          0x1920a3388 -[UILayoutContainerView layoutSubviews] + 188
17 UIKit                          0x191fe9cc0 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1200
18 QuartzCore                     0x18f1da274 -[CALayer layoutSublayers] + 148
19 QuartzCore                     0x18f1cede8 CA::Layer::layout_if_needed(CA::Transaction*) + 292
20 QuartzCore                     0x18f1ceca8 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32
21 QuartzCore                     0x18f14a34c CA::Context::commit_transaction(CA::Transaction*) + 252
22 QuartzCore                     0x18f1713ac CA::Transaction::commit() + 504
23 QuartzCore                     0x18f171e78 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 120
24 CoreFoundation                 0x18be689a8 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
25 CoreFoundation                 0x18be66630 __CFRunLoopDoObservers + 372
26 CoreFoundation                 0x18bd96dc4 CFRunLoopRunSpecific + 456
27 UIFoundation                   0x191f95134 -[NSHTMLReader _loadUsingWebKit] + 1764
28 Foundation                     0x18c9af50c __NSThreadPerformPerform + 340
29 CoreFoundation                 0x18be6942c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
30 CoreFoundation                 0x18be68d9c __CFRunLoopDoSources0 + 540
31 CoreFoundation                 0x18be669a8 __CFRunLoopRun + 744
32 CoreFoundation                 0x18bd96da4 CFRunLoopRunSpecific + 424
33 GraphicsServices               0x18d801074 GSEventRunModal + 100
34 UIKit                          0x192051c9c UIApplicationMain + 208
35 iPhoneHandheldACT              0x1000a7bf4 main (main.m:16)
36 libdyld.dylib                  0x18ada559c start + 4

在第 8 行,您似乎已经在 inDatabase 呼叫中(即,当您再次尝试进入队列时,您已经在 FMDatabaseQueue 中)。当您已经在串行队列中时,不要尝试进入串行队列。充其量,你会陷入僵局。如果您在错误的时间执行此操作(例如在应用程序启动期间),看门狗进程将终止您的应用程序,异常代码为 0x8badf00d("ate bad food";大声笑;请参阅 Technical Note TN2151: Understanding and Analyzing Application Crash Reports)。