App Hang: The app was terminated while unresponsive

283 Views Asked by At

I try to upload a large dataset into the SQLite database using FMDB.
My app gets hang and kills when I continuously shift between background and foreground thread.

Someone, please suggest to me how to use multithreading with this.
I checked in the instruments app, it shows the server hang on the main thread
I am using this code of FMDB to upload data into the database

sharedQueue.inDeferredTransaction { (db, rollback) in
    do {
        if !sharedDatabase.isOpen {
            sharedDatabase.open()
        }
        try sharedDatabase.executeUpdate(sqlStatement, values: values)
        completion(true, nil)
        sharedDatabase.close()
        print("FMDB INSERT Success")
    } catch {
        print("FMDB INSERT failed: \(error.localizedDescription)")
        completion(false, error)
        sharedDatabase.close()
    }
}

Here are the crash logs

CrashReporter Key:  113c7cbb69fb95c4d22805670b7048e73e4e72d7

Hardware Model:     iPhone11,8

Process:            PurplePlayer

Identifier:...

Version:            5.0

Role:               Foreground

OS Version:         iOS 16.5.1

App Hang: The app was terminated while unresponsive

0  libsystem_kernel.dylib +0x295c \_guarded_pwrite_np

1  libsqlite3.dylib +0x8e50c      0x1abfc250c (0x1abfc2348 + 452)

2  libsqlite3.dylib +0x4bb68      0x1abf7fb68 (0x1abf7fab8 + 176)

3  libsqlite3.dylib +0x53acc      0x1abf87acc (0x1abf87980 + 332)

4  libsqlite3.dylib +0x47a8c      0x1abf7ba8c (0x1abf7b7d4 + 696)

5  libsqlite3.dylib +0x4b4d0      0x1abf7f4d0 (0x1abf7f3ac + 292)

6  libsqlite3.dylib +0x4ad74      0x1abf7ed74 (0x1abf7e520 + 2132)

7  libsqlite3.dylib +0x32984      0x1abf66984 (0x1abf6002c + 26968)

8  libsqlite3.dylib +0x2b5b0      \_sqlite3_step

9  FMDB +0x9994                   -\[FMDatabase executeUpdate:error:withArgumentsInArray:orDictionary:orVAList:\]

10 FMDB +0xa150                   -\[FMDatabase executeUpdate:values:error:\]

11 PurplePlayer +0x18f1e8         closure #1 in static FMDBDatabase.update(sqlStatement:values:completion:)

12 PurplePlayer +0x29678          thunk for @callee_guaranteed (@guaranteed FMDatabase, @unowned UnsafeMutablePointer\<ObjCBool\>) -\> ()

13 PurplePlayer +0x296f8          thunk for @escaping @callee_guaranteed (@guaranteed FMDatabase, @unowned UnsafeMutablePointer\<ObjCBool\>) -\> ()

14 FMDB +0x10370                  \__46-\[FMDatabaseQueue beginTransaction:withBlock:\]\_block_invoke

15 libdispatch.dylib +0x6034      \_dispatch_client_callout

16 libdispatch.dylib +0x17810     \_dispatch_lane_barrier_sync_invoke_and_complete

17 FMDB +0x10214                  -\[FMDatabaseQueue beginTransaction:withBlock:\]

18 FMDB +0x10498                  -\[FMDatabaseQueue inDeferredTransaction:\]

19 PurplePlayer +0x18ef78         static FMDBDatabase.update(sqlStatement:values:completion:)

20 PurplePlayer +0x18f7b0         static FMDBDatabase.insert(values:sqlStatement:completion:)

21 PurplePlayer +0x1837c0         LiveTvFMDBTable.insertLiveTVData(tbl:liveTvModel:categoryName:playlistId:)

22 PurplePlayer +0x61f04          closure #1 in FetchingDataViewModel.StoreRetriveAndReloadTable(livetvData:tbl:playlistId:)

23 PurplePlayer +0x61f70          partial apply for closure #1 in FetchingDataViewModel.StoreRetriveAndReloadTable(livetvData:tbl:playlistId:)

24 libswiftCore.dylib +0x16604    Collection.map\<A\>(\_:)

25 PurplePlayer +0x61afc          FetchingDataViewModel.StoreRetriveAndReloadTable(livetvData:tbl:playlistId:)

26 PurplePlayer +0x61770          closure #1 in FetchingDataViewModel.insertDataintoDatabase(livetvData:playlistId:tbl:completion:)

27 PurplePlayer +0x617a4          partial apply for closure #1 in FetchingDataViewModel.insertDataintoDatabase(livetvData:playlistId:tbl:completion:)

28 libswiftCore.dylib +0x16604    Collection.map\<A\>(\_:)

29 PurplePlayer +0x616b4          FetchingDataViewModel.insertDataintoDatabase(livetvData:playlistId:tbl:completion:)

30 PurplePlayer +0x5e150          closure #1 in closure #1 in closure #1 in FetchingDataViewModel.callLiveTVApis(\_:)

31 PurplePlayer +0x612c4          specialized closure #1 in FetchingDataViewModel.callLiveTVAPi(action:\_:)

32 PurplePlayer +0x883d4          closure #1 in APIManager.request\<A\>(urlString:method:parameters:isShowLoader:completion:)

33 Alamofire +0xddf94             closure #1 in closure #1 in closure #3 in closure #1 in DataRequest.\_response\<A\>(queue:responseSerializer:completionHandler:)

34 Alamofire +0x208ec             thunk for @escaping @callee_guaranteed () -\> ()

35 libdispatch.dylib +0x451c      \_dispatch_call_block_and_release

36 libdispatch.dylib +0x6034      \_dispatch_client_callout

37 libdispatch.dylib +0x16794     \_dispatch_main_queue_drain

38 libdispatch.dylib +0x162d8     \_dispatch_main_queue_callback_4CF

39 CoreFoundation +0x98c24        \___CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE_\_

40 CoreFoundation +0x7a55c        \___CFRunLoopRun

41 CoreFoundation +0x7f3e8        \_CFRunLoopRunSpecific

42 GraphicsServices +0x1358       \_GSEventRunModal

43 UIKitCore +0x39d6e4            -\[UIApplication \_run\]

44 UIKitCore +0x39d348            \_UIApplicationMain

45 libswiftUIKit.dylib +0x350ac   UIApplicationMain(\_:\_:\_:\_:)

46 PurplePlayer +0x3f4ca8         static UIApplicationDelegate.main()

47 PurplePlayer +0x3f4c20         static AppDelegate.$main()

48 PurplePlayer +0x3f502c         main

49 dyld +0x15de8                  start
0

There are 0 best solutions below