When I get app on background mode, app crashed with log below.
This is device log of crash :
Exception Type:  EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Termination Reason: Namespace ASSERTIOND, Code 0x8badf00d
Triggered by Thread:  0
Filtered syslog:
None found
Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib        0x0000000183563de8 mach_msg_trap + 8
1   libsystem_kernel.dylib          0x0000000183563c60 mach_msg + 72
2   CoreFoundation                  0x0000000183aa6e40 __CFRunLoopServiceMachPort + 196
3   CoreFoundation                  0x0000000183aa4908 __CFRunLoopRun + 1568
4   CoreFoundation                  0x00000001839c4da8 CFRunLoopRunSpecific + 552
5   GraphicsServices                0x00000001859aa020 GSEventRunModal + 100
6   UIKit                           0x000000018d9e4758 UIApplicationMain + 236
7   AijouNetto                      0x00000001008a851c main + 410908 (AppDelegate.swift:17)
8   libdyld.dylib                   0x0000000183455fc0 start + 4 
This the class implementation :
class EKNBackgroundTaskManager {
let backgroundDQ = DispatchQueue.global(qos: .background)
var backgroundUpdateTask: UIBackgroundTaskIdentifier!
init(withName: String) {
    self.backgroundUpdateTask = UIApplication.shared.beginBackgroundTask(withName: withName) {}
}
func runBackgroundTask(withCode: @escaping (_ cH: @escaping () -> Void) -> Void)
{
    backgroundDQ.async {
        withCode() {
            self.endBackgroungTask()
        }
    }
}
func endBackgroungTask() {
    if backgroundUpdateTask != nil && backgroundUpdateTask != UIBackgroundTaskInvalid {
        UIApplication.shared.endBackgroundTask(backgroundUpdateTask)
        backgroundUpdateTask = UIBackgroundTaskInvalid
    }
  }
}
Any advice to fix this bug while application become in background mode ?