簡體   English   中英

在后台模式下打開FMDB時崩潰

[英]Crash when opening FMDB in background mode

我的iOS上的Cordova應用程序從一個重大的位置更改啟動,有時以這種方式啟動時,在打開數據庫時崩潰。 我不確定是什么情況導致的-我自己無法復制它,我剛收到有關Crashlytics的報道; 它似乎只影響某些設備。

這是我的代碼:

class Database {
    static let DB_DIR:URL = {
        // Library/LocalDatabase doesn't get backed up to iTunes/iCloud, and it matches our sqlite plugin's default (for Javascript access)
        let fileMgr = FileManager.default
        let libUrl:URL = try! fileMgr.url(for: .libraryDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
        return libUrl.appendingPathComponent("LocalDatabase")
    }()

    static func getPath(_ dbName:String!) -> String {
        return DB_DIR.appendingPathComponent(dbName).path
    }

    static func createDb(_ dbName:String!) -> FMDatabase {
        return FMDatabase(path: getPath(dbName))
    }

    // only for front- and back-end dbs (TODO - close these when app exits, or open/close for each transaction?)
    static func getOpenedDb(_ dbName:String) -> FMDatabase {
        let db:FMDatabase = createDb(dbName)
        if !db.open() {
            fatalError("Unable to open \(dbName)")
        }
        return db
    }

    static let BACKEND_DB:FMDatabase = Database.getOpenedDb("mainIosDb")
    static let FRONTEND_DB:FMDatabase = Database.getOpenedDb("JsDb")    
}

...這是崩潰日志:

Crashed: com.rsginc.rmove.TripStorage.singleton
0  libswiftCore.dylib             0x1008c8a18 _TFs16_assertionFailedFTVs12StaticStringSSS_Su5flagsVs6UInt32_Os5Never + 164
1  rMove                          0x10022dc88 type metadata accessor for Database (Utilities.swift)
2  rMove                          0x10022d320 globalinit_33_2CFFAAA7EF6073F07DB88164E80B793B_func11 (Utilities.swift:177)
3  libdispatch.dylib              0x188c6e1bc _dispatch_client_callout + 16
4  libdispatch.dylib              0x188c6efb0 dispatch_once_f + 56
5  rMove                          0x10022d35c Database.BACKEND_DB.unsafeMutableAddressor (Utilities.swift)
6  rMove                          0x100213864 TripStorage.init() -> TripStorage (TripStorage.swift:13)
7  rMove                          0x100213508 static TripStorage.(getInstance() -> TripStorage).(closure #1) (TripStorage.swift:87)
8  libdispatch.dylib              0x188c6e1bc _dispatch_client_callout + 16
9  libdispatch.dylib              0x188c7b7f0 _dispatch_barrier_sync_f_invoke + 84
10 rMove                          0x100213418 static TripStorage.getInstance() -> TripStorage (TripStorage.swift)
11 rMove                          0x10020384c specialized CordovaInterface.start(Double, Double, Int, Double, Double, String, Bool, Int, Int, Double, Int, Int, Int, Int) -> () (CordovaInterface.swift)
12 rMove                          0x1001fea74 CordovaInterface.configureFromDefaults() -> () (CordovaInterface.swift)
13 rMove                          0x1002014fc partial apply (CordovaInterface.swift)
14 rMove                          0x10020b1e0 specialized TerminationRecovery.applicationLaunched(notification : NSNotification) -> () (TerminationRecovery.swift)
15 rMove                          0x10020a020 @objc TerminationRecovery.applicationLaunched(notification : NSNotification) -> () (TerminationRecovery.swift)
16 CoreFoundation                 0x189d7eb10 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
17 CoreFoundation                 0x189d7e214 _CFXRegistrationPost + 400
18 CoreFoundation                 0x189d7df90 ___CFXNotificationPost_block_invoke + 60
19 CoreFoundation                 0x189dedb8c -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1504
20 CoreFoundation                 0x189cbfe64 _CFXNotificationPost + 376
21 Foundation                     0x18a7f4e0c -[NSNotificationCenter postNotificationName:object:userInfo:] + 68
22 UIKit                          0x18ff1cd38 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4196
23 UIKit                          0x18ff22808 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1656
24 UIKit                          0x18ff37104 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke.3139 + 48
25 UIKit                          0x18ff1f7ec -[UIApplication workspaceDidEndTransaction:] + 168
26 FrontBoardServices             0x18b9bb92c __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36
27 FrontBoardServices             0x18b9bb798 -[FBSSerialQueue _performNext] + 176
28 FrontBoardServices             0x18b9bbb40 -[FBSSerialQueue _performNextFromRunLoopSource] + 56
29 CoreFoundation                 0x189d92b5c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
30 CoreFoundation                 0x189d924a4 __CFRunLoopDoSources0 + 524
31 CoreFoundation                 0x189d900a4 __CFRunLoopRun + 804
32 CoreFoundation                 0x189cbe2b8 CFRunLoopRunSpecific + 444
33 UIKit                          0x18fd057b0 -[UIApplication _run] + 608
34 UIKit                          0x18fd00534 UIApplicationMain + 208
35 rMove                          0x100103b00 main (main.m:32)
36 libdispatch.dylib              0x188ca15b8 (Missing)

堆棧跟蹤中的這一行:

2 rMove 0x10022d320 globalinit_33_2CFFAAA7EF6073F07DB88164E80B793B_func11 (Utilities.swift:177)

與代碼中的這一行相對應:

static let BACKEND_DB:FMDatabase = Database.getOpenedDb("mainIosDb")

我的猜測和希望是,堆棧跟蹤中有一些很棒的信息,這些信息直接指出了此問題的起因,而我只是不知道如何解釋它。

您必須使用標志打開數據庫,嘗試對我有用的belloe代碼

[self.database openWithFlags:SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FILEPROTECTION_NONE];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM